[EMAIL PROTECTED] (Luke Palmer) writes:
> I would hope the former.  However, what about this
compile-time
> integral power macro[1]?
> 
>     macro power ($x, $p) {
>         if $p > 0 {
>             { $x * power($x, $p-1) }
>         }
>         else {
>             { 1 }
>         }
>     }
> 
> That would hopefully turn:
> 
>     my $var = 10;
>     print power $var, 4;
> 
> Into
> 
>     print($var * $var * $var * $var * 1);

The full answer to this would be partial evaluation.
See:
http://www.dina.dk/~sestoft/pebook/

Partial evaluators exist for languages like scheme, ML
and even C (don't 
look at the C one for a clean example!). A partial
evaluator simplifies 
a function given some of its inputs. This can be quite
powerful: if P is a
partial evaluator, I an interpreter, and C some code,
then P(I,C)  is a 
compiled version of C, and P(P,I) is a compiler.
P(P,P) is a compiler 
generator. But the original code needs to be written
with an eye for
how it will be simplified or you just get the same
code back with the 
data tacked on the front.

In theory I guess you could write a partial evaluator
as a perl6 macro,
thus avoiding the need to parse the code (although it
would be more 
convenient if you could pass it the syntax tree of a
previously defined 
function, rather than having to quote it - unless I've
missed a way of 
doing just that).

But I confidently predict that no-one will write a
useful partial 
evaluator for perl6. The language is simply too big.

Alex




__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Reply via email to