If you understand how compilers work,what ’s really going on is not so much that Lisp has a strange syntax as that Lisp has no syntax.You write programs in the parse trees that get generated within the compiler when other languages are parsed.But these parse trees are fully accessible to your programs.You can write programs that manipulate them.In Lisp,these programs are called macros.They are programs that write programs.We're talking about manipulating the parse tree after the front-end "syntax" of the language is all gone. Optree manipulation is close to that. In my own musings in the past, I thought about having an explicit intermediate tree form that can be manipulated in this manner, without having to actually write in it in the first place.
Now Perl 6 will have extensible grammers. To change the grammer, you will have to know the underlying parse tree structure so you can write new productions that are meaningful to the next stage.
This means that the parse tree stage as an abstract representation of the program will be documented and stable, sort of like the interface designed for derived classes to use.
Already Perl interleaves compile and run phases, and this is how pragmatic imports work. Actually, all imports are "pragmas", in that they work by manipulating the caller's symbol table before compilation continues forward.
So, I wonder what it would take to have a Perl feature similar to what LISP calls Macros, and I fully-qualify as a parse-tree macro?
I think the crux of the matter is to make it implictly a BEGIN block, just like use is today. A function that was implicitly called as immediatly after compiling the call to it could contain code to manipulate the compiler's state such as the flags and symbol table (as import does today) and the parse tree in progress, using the hypothisized abilities.
Knowing this, I wonder if the component features can be tweeked in the design phase to better support this emergence.
Feel free to pass this along to anyone interested.
—John
In reply to Parse-Tree Macros : from LISP to Perl 6? by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |