While we seem to be on the subject of hashing out macro semantics,
here's a question I've had awhile.
What do macros do about being passed variables?
Let's say I make a C<square> macro:
macro square ($x) {
{ $x * $x }
}
And then I have code.
my $var = 10;
print square $var;
Does that turn that into (at compile time):
print($var * $var);
Or does it use the compile time value of $x, turning it into:
print(undef * undef);
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);
But what about
my $var = 10;
my $ex = 4;
print power $var, $ex;
Thanks.
Luke
[1] That one's kind of interesting actually. If the macro is called
right upon parsing it, it will be called before it's done compiling
it. Which is a problem. Is there a way to get around this, because
recusive macros are useful (as demonstrated above).
Luke