in reply to Parse-Tree Macros : from LISP to Perl 6?

The reason you can do this so easily in lisp is because you're actually writing the parse tree by hand--lisp has no syntax to speak of.

The reason you have to do this in lisp is because lisp has no syntax to speak of, and if you actually want any you need to roll it yourself. (Not, mind, that you can actually get syntax with macros, since a macro-ized lisp program is still a lisp program)

You'll have access to the AST the perl parser generates, and can manipulate it as you see fit before it goes to the compiler, though you'll find, I think, that you'll want (and have) to do this far less often in perl than you might in lisp.

Also be aware that this will be one of the features you'll most want to kill someone for using, if someone actually uses it. With great power comes great fuck-ups. (This is true in the Lisp community as well, which should be very, very worrisome. There are very few non-uber-hackers in the lisp world, as that sort of folk use other, more useful and less painful languages. And if the scary-smart people mess it up, well...)

If past history is anything to go by, the first word you should utter when you hear someone say "I can mess with the parse tree!" is... Don't!

  • Comment on Re: Parse-Tree Macros : from LISP to Perl 6?

Replies are listed 'Best First'.
Re^2: Parse-Tree Macros : from LISP to Perl 6?
by diotalevi (Canon) on Nov 27, 2002 at 01:14 UTC

    I can mess with the opcode tree ... I did eventually get farther with that code but never quite got it working. I blame it on my own incompetance at optree hacking. Seriously... B::Generate is quite the awesome module. There are other more mundane uses for this but it's still quite fun for just this one anyway.

    Update: Oh duh. Ok well I did this in perl 5 which is offtopic from John's perl6 question but I rather expect (for no particular reason) that such hackery will become even easier for perl6

    __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

      I wouldn't be too sure about that. I doubt that the ability to hack the optree will be a central goal in the desing of the perl6 compiler. However, the compiler isn't anywhere near completed yet, so its probably too early to jump to any sort of conclusion about it.

      However, it should be possible to get at the intermediate compilition step, although it won't be as easy to manipulate.