[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 complete answer to this would be partial evaluation. Partial
evaluators exist for langauges such as lisp, ML, and even C. See
http://www.dina.dk/~sestoft/pebook/pebook.html

A partial evaluator simplifies a function with respect to some of its
inputs, if possible. This can be quite powerful: If P is a partial
evaluator, I an interpreter, and C some code, the P(I,C) compiles C
(in a rudimentary sort of way) and P(P,I) produces a compiler. But
code has to be written with an eye to making it possible to simplify it,
otherwise you just get the original code back.

In theory you could write one as a perl6 macro, although it would be
more convenient if there was someway of obtaining the syntax tree of a
previously defined function other than quoting it (unless I've missed
that?).  
But I confidently predict that no-one with write a useful partial
evaluator for perl6. The language is simply too big.

Alex


Reply via email to