News for hackers. Stuff that matters.
Re:Lisp Meta-Programming for C++ Developers: First Macros by progman on Tuesday May 09, 2017 @11:58AM (#14301111)
Side effects are no issue if every local variable name in a defmacro is generated with (gensym).
Re:Lisp Meta-Programming for C++ Developers: First Macros by TeMPOraL on Tuesday May 09, 2017 @12:18PM (#14301276)
And if you're tired of doing that by hand, you can... write a macro that'll do that for you. In fact, those were already written, and are available in many libraries as well as featured in many books.

See e.g. Alexandria[0] for with-gensyms (automatically binding your variables to gensyms) and once-only (similar, but ensures the value will be evaluated only once).

Also note that lack of hygiene is actually a useful feature - it allows macros to capture variables from code passed to it as well as the environment they expand it. Some cool stuff can be done that way (some uncool foot-shooting too, though).

--

[0] - https://common-lisp.net/project/alexandria/draft/alexandria....

Re:Lisp Meta-Programming for C++ Developers: First Macros by sedachv on Tuesday May 09, 2017 @03:35PM (#14303155)
> Also note that lack of hygiene is actually a useful feature - it allows macros to capture variables from code passed to it as well as the environment they expand it. Some cool stuff can be done that way (some uncool foot-shooting too, though).

Doug Hoyte's excellent book _Let Over Lambda_ has a lot of examples.

Re:Lisp Meta-Programming for C++ Developers: First Macros by TeMPOraL on Tuesday May 09, 2017 @04:31PM (#14303555)
Oh yes. This book is very fun, in the "what on Earth did he just do here" kind of way.
Re:Lisp Meta-Programming for C++ Developers: First Macros by Johnny_Brahms on Tuesday May 09, 2017 @03:56PM (#14303292)
Syntax-case allows you to introduce bindings into the lexical context (breaking hygiene in a very controlled manner). It does not work with lists, but with syntax objects.
Re:Lisp Meta-Programming for C++ Developers: First Macros by nyir on Tuesday May 09, 2017 @12:16PM (#14301245)
Exactly, you have to specify what you want. Evaluating an expression argument multiple times is probably a mistake, as is not having a new gensym for local variables ... until it is not, e.g. for anaphoric macros (binding some value to "it", https://en.wikipedia.org/wiki/Anaphoric_macro, you can still argue that that's bad style of course).