I have been writing Lisp macros for 20 years or more, and I’m now taking a look into Scala macros. But there are some things which are puzzling. In Lisp, macros take advantage of the homoiconicity of the language, i.e., that the code is a data structure which code can manipulate. It appears to me that Scala macros take an argument (perhaps some arguments, not sure) which are ASTs. So how can I pass literal values to a macro? Must any value I pass be valid Scala code? If so, have all the macros within that code already been expanded?
In Lisp (in particular Common Lisp, but also in emacs lisp) the operands of the macro need not be valid lisp code, in the sense that it need not be compilable as is, but rather is simply a data structure of what the user typed. If the user provided a malformed if/then/else for example, then the macro will see the malformation. The macro writer can and often does take advantage of this feature in allowing macros to extend the syntax. For trivial example, I could write a macro which allows the user to use if/else/then …
One possibility I though about to work around this Scala limitation is to pass an object to the macro, and let the macro inspect the object to make its decisions. However, as I understand it, the macro would not actually receive the object, but instead would receive an AST which evaluated at runtime would produce the object. How can I access the actual object within the macro? Do I need to somehow EVAL the AST?
I’d appreciate any help someone can provide. I’m also happy to give more details about the particular application I’m trying to implement.