<?xml version="1.0" encoding="windows-1252"?>
<node id="265209" title="Re: Re: Macros, LFSPs and LFMs" created="2003-06-11 18:20:55" updated="2005-08-12 10:08:44">
<type id="11">
note</type>
<author id="186362">
adrianh</author>
<data>
<field name="doctext">
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;On the other hand, I'd also like to see a few examples of what people would use a macro facility for in Perl. Assuming that p5 had a C-like&lt;/em&gt;&lt;/p&gt;
&lt;code&gt;
#define name(arg[,arg]) {\
 some code here\
 }
&lt;/code&gt;
&lt;/blockquote&gt;

&lt;p&gt;I wouldn't use it for C-like purposes. C-like macros are not that powerful - you can only do basic textual substitutions. To quote [http://www.perl.com/pub/a/2003/04/09/synopsis.html|Synopsis 6]:&lt;/p&gt;

&lt;blockquote&gt;
Macros (keyword: macro) are routines whose calls execute as soon as they are parsed (i.e. at compile-time). Macros may return another source code string or a parse-tree.
&lt;/blockquote&gt;

&lt;p&gt;Returning a parse-tree is where it gets interesting. What we get here are LISPish macros. We'll be able to write code that's run at compile time to create our own syntax.&lt;/p&gt;

&lt;p&gt;Want a switch statement in Perl6? Just write one.&lt;/p&gt;

&lt;p&gt;Want to add AOP or Design by Contract support to Perl6? Just write some new syntax.&lt;/p&gt;

&lt;p&gt;Want to create a domain-specific language so you can write code that more directly reflects the problem domain? Yes - you guessed it - just write some new syntax!&lt;/p&gt;

&lt;p&gt;There's a [http://groups.google.com/groups?threadm=20021023214308.GA746%40chianti|discussion of macros] on perl.perl6.language that you might find interesting. Also read the relevant bit of [http://www.perl.com/pub/a/2003/03/07/apocalypse6.html?page=9|Apocalypse 6].&lt;/p&gt;

&lt;p&gt;Macros - can't wait ;-)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Just come across [id://163877], which has some relevant material for those who are interested.&lt;/p&gt;</field>
<field name="root_node">
265084</field>
<field name="parent_node">
265146</field>
</data>
</node>
