"Austin Hastings" <[EMAIL PROTECTED]> writes: > [Eirik wrote:] > > Let us see ... somewhat speculative and probably short-of-the-mark > > generalization coming up: > > > > > > macro infix:[ ($lhs, $op, $rhs) > > is parsed(/(<Perl6.expr>) \] (<Perl6.expr>)/) { > > return { > > $op($lhs, $rhs) > > }; > > } > > > > (Precedence? Err ... the left hand side has already been parsed, > > so infix:[ must be of fixed precedence to the left hand side, right? > > Damn, I thought I had it ...) > > This is text replacement, not expression evaluation. You do have it from > where I sit.
Text replacement? This is returning a closure, not text. But even if this is a case of text replacement, I get the first parameter, $lhs, from text that has already been parsed. > # Note: Need a way to parse nested []'s > macro [ ($whosit) is parsed(/(<?:\s[) (<expr>) \]/) { > eval $whosit; > } I may not be up-to-date on macros and is parsed, but ITYM: macro prefix:[ ($whosit) is parsed(/(<Perl6.expr>) \]/) { return eval $whosit; } This should return text, I believe. But the parser will not be expecting a term (or prefix:-operator) here ... it is looking for an infix:-operator or a postfix:-operator, right? (And it will eval() at compile time, so my phase-of-the-moon example will not be evaluated at run time, even if this works.) > The macro immediately evaluates the expression, so it has to be a deferrable > reference. > Then: > > macro infix:eqn($n) is equiv (&infix:eq) { > "[&String::strncmp.assuming(n => 4)]" > } (s/4/\$n/, I believe.) But the infix:-operators by default get their LHS and RHS parse trees as parameters, last I heard, so your parameter list is too short. Still, you may be on to something ... what about this? macro infix:eqn ($lhs, $n, $rsh) is equiv(&infix:eq) is parsed(/ \( (<Perl6.expr>) \) (<Perl6.expr but speculatively_equiv(&infix:eq)>)/) { return "String::strncmp($lhs, ($rhs), ($n))"; } if "Dough" eqn(4) "Douglas" {...} becomes if String::strncmp("Dough", ("Douglas"), (4)) {...} Okay, that may be evil. But it DWYW, right? No such luck with my phase-of-the-moon example, though. And come to think of it, finding the right precedence might be tricky, even if this (or more complicated re-parsing tricks) should happen to work: macro infix:[ ($lhs, Sub $op, $rhs) is equiv($op) is parsed(/(<Perl6.expr>) \] (<Perl6.expr but speculatively_equiv($op)>)/) { return "($op).(($lhs), ($rhs))"; } # This might be determinable at compile time: if $test [$moon.is_waxing ? &infix:< : &infix:>=] $target {...} # This would need explicit "but equiv" or something like that: if $test [($lookup{$key} || &infix:eq) but equiv(&infix:eq)] $target {...} So, probably just a bad idea. Eirik -- All bridge hands are equally likely, but some are more equally likely than others. -- Alan Truscott