Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Macros 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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: