4 ms·
My naive interpretation of `defmacro` is passing data into a function to return another function. From my python POV that would be the same as returning a calla
by halkony 4y ago
My naive interpretation of `defmacro` is passing data into a function to return another function. From my python POV that would be the same as returning a callable from a function (decorators being one example).
I think top comment does a good job explaining that while I'd get the same functional result, Python objects have tons of abstraction behind them that make them harder to work with than lisp combinations.
- Jtsummers 4y agoMacros don't (necessarily) return functions. They take a set of values and then produce an s-expression, which in turn is read by the reader and evaluated. For instance a user-created `when` macro would be something like this (not tested): (defmacro when (condition &body body) `(if ,condition (progn ,@body))) That's not a new function that's been returned, just a new expression which can then be read (and macro expansion can be a repeated process as its read so you can use nested macros in macros in macros, even recursive macros but take care there). You can use macros as you describe, in a manner similar to a Python decorator, but that's only one of many possible uses.