Hacker News new | ask | show | jobs
by ghusbands 5203 days ago
For Common Lisp, think also of reader macros.

Similarly, in syntactically richer languages, macros could add syntactic constructs that are not akin to function application. With sufficiently powerful macros, you can add, for example, new infix operators, a new form of switch/case or a new way to declare variables.

1 comments

Scala already has plenty of syntactic sugar for chaining method calls, so you can write stuff like:

myObj explode 10 times

which translates into myObk.explode.10.times()

Through the magic of implicits, you can make any builtin type auto-cast to your wrapper type, so there really is no need for syntactic macros - scala is already DSL-enabled.

I agree that Scala's excellent implicits, syntactic sugar, destructuring and other pattern matching indeed cover a great number of typical macro use-cases, but to say there is "no need" may be a little strong. http://scalamacros.org/usecases/ lists a number of improvements macros can bring over current Scala syntax for some operations.
My experience has been that these features are great but not free. I often have to choose between writing expressive, elegant, DRY code that is mind-numbingly slow or writing Fortran in Scala. Much of the time our needs are better met by writing Fortran in Scala, but with a macro system it would at least be DRY Fortran.
It translates to myObk.explode(10).times.