How far can LISP macros go? [closed]

That’s a really good question.

I think it’s nuanced but definitely answerable:

Macros are not stuck in s-expressions. See the LOOP macro for a very complex language written using keywords (symbols). So, while you may start and end the loop with parentheses, inside it has its own syntax.

Example:

(loop for x from 0 below 100
      when (even x)
      collect x)

That being said, most simple macros just use s-expressions. And you’d be “stuck” using them.

But s-expressions, like Sergio has answered, start to feel right. The syntax gets out of the way and you start coding in the syntax tree.

As for reader macros, yes, you could conceivably write something like this:

#R{
      ruby.code.goes.here
  }

But you’d need to write your own Ruby syntax parser.

You can also mimic some of the Ruby constructs, like blocks, with macros that compile to the existing Lisp constructs.

#B(some lisp (code goes here))

would translate to

(lambda () (some lisp (code goes here)))

See this page for how to do it.

Leave a Comment