Cool stuff. In my usual pedantic sort of way, I'll go through the
message and fix everything you said. For educational purposes only, of
course :-)
Eirik Berg Hanssen writes:
> Luke Palmer <[EMAIL PROTECTED]> writes:
>
> > Hmm, since we're requiring no whitespace between a variable and it's
> > subscript, this should be possible:
> >
> > if "Dough" [eqn 4] "Douglas" {...}
>
> Lisp! :-)
>
> Well, almost. Now this would be lisp-y:
>
> if $test [$moon.is_waxing ? &infix:< : &infix:>=] $target {...}
if $test [$moon.is_waxing ?? &infix:< :: &infix:>=] $target {...}
> 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)
> };
> }
Pretty close.
# Let's say C<is parsed> args come before the default infix args
macro infix:[ ($op, $lhs, $rhs)
is parsed( /:w (<Perl6.expr>) \]/ )
{
my ($clhs, $crhs) = [$lhs, $rhs]損.束compile; #only compile once
return {
$op($clhs.run, $crhs.run);
}
}
This would have the precedence of &infix:+ .
> (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 ...)
You shouldn't parse the right hand side yourself. That fixes the issue.
Note that this is just how ??:: is going to do things:
macro infix:?? ($iftrue, $cond, $iffalse)
is parsed( /:w (<Perl6.expr>) <'::'>/ )
is tighter(&infix:=)
is assoc('right')
{
my ($ccond, $ciftrue, $iffalse) = [$iftrue, $cond, $iffalse]損.束compile;
return {
if $ccond.run {
$ciftrue.run;
}
else {
$ciffalse.run;
}
}
}
And there might just be a C<is compiled> trait to automatically do that
first line. If not, it will surely be defined in Macro::Common. :-)
> Then vector operators, like >>+<<, are "really" just simple
> [vectorize &infix:+] and similar -- except properly optimized and
> presumably with proper precedence.
Yeah. Very cool.
> And, you can write:
>
>
> if "Dough" [&String::strncmp.assuming(n => 4)] "Douglas" {...}
>
>
> Still long. Oh well. infix:[eqn, perhaps?
Do you I<want> to give me a heart attack? :-/
This would be fine, I think:
sub eqn ($n) { &String::strncmp.assuming(n => $n) }
> At least that one will be of fixed precedence. Right?
>
>
> macro infix:[eqn ($lhs, $n, $rhs)
> is equiv(&infix:eq)
> is parsed(/(<Perl6.expr>)
> \]
> (<Perl6.expr but speculatively_equiv(&infix:eq)>)/) {
> return {
> String::strncmp($lhs, $rhs, n => $n)
> };
> }
I can't feel my left arm...
Again, you don't need to parse the right side of the operator yourself,
otherwise it be a postfix: macro.
Luke