Re:Hy – A dialect of Lisp that’s embedded in Python
by foobarian on Wednesday December 03, 2014 @09:26PM
(#8697572)
> but the macro actually has access to the the "program code", so you can do arbitrary transformations.
I like to compare the way lisp works to Javascript and the DOM. Just like a webpage (or its JS code) has access to its internal structure and can do arbitrary transformations, so does lisp except instead of the DOM you have the abstract syntax tree.
The implementation is easier if you assume that you have exactly two generators. Here is an example in Racket. It uses define-syntax-rule that is the method to define simple macros (there are more advanced options).
(The program also define string->list/string that splits a list in a list of one-character string, because the result of string->list is a list of chars. You can ignore it safety.)