# New Ticket Created by "Carl Mäsak" # Please include the string: [perl #115566] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=115566 >
<jnthn> r: macro infix:<pos-or>(*@asts) is assoc('list') { my $result = @asts.pop; for @asts.reverse { $result := quasi{ {{{$_}}} > 0 ?? {{{$_}}} !! {{{$result}}} } }; $result }; sub foo() { say "oops"; 4 }; say -5 pos-or 3 pos-or foo; <p6eval> rakudo 2bb302: OUTPUT«3» <jnthn> Using two of the month's new features together :P <masak> that's pretty impressive. <jnthn> Sadly, fixing the double evaluation exposes a bug. <jnthn> r: macro infix:<pos-or>(*@asts) is assoc('list') { my $result = @asts.pop; for @asts.reverse { $result := quasi { my \x = {{{$_}}}; x > 0 ?? x !! {{{$result}}} } }; $result }; sub foo() { say "oops"; 4 }; say -5 pos-or 3 pos-or foo; <p6eval> rakudo 2bb302: OUTPUT«Lexical 'x' not found in at /tmp/tiE6e4uirM:1 in block at /tmp/tiE6e4uirM:1» <masak> "the double evaluation"? <jnthn> masak: It evalutes the macro argument twice. <jnthn> masak: Because I wrote it that way <masak> oh! <masak> (phew) <jnthn> {{{$_}}} > 0 ?? {{{$_}}} !! ... <masak> yes, each {{{}}} evaluates once. <jnthn> And I wanted to just do it once, but when I try to stick it in a temporary variable, it busts. <masak> as above. I see. <masak> maybe declaring variables in quasis doesn't work? <jnthn> Seems so <masak> r: macro foo { quasi { my $a = "OH HAI"; say $a } }; foo <p6eval> rakudo 2bb302: OUTPUT«Cannot assign into a PMCNULL container [...] * masak submits rakudobug