On Thu, Aug 28, 2008 at 08:32:41AM -0700, Carl Mäsak wrote:
> r30590:
> $ ./perl6 -e 'regex a { b }; "b" ~~ a'
> too few arguments passed (0) - 2 params expected
> [...]
> 
> I've also added tests for this in t/spec/S05-metasyntax/regex.t.
> 
> (S05 is not entirely clear as to whether this should actually work.
> IMHO, there's noreason for it not to. Storing anonymous regexes in
> scalar variables already works.)
> 
> $ ./perl6 -e 'my $a = regex { b }; say "b" ~~ $a'
> b

For now I'm going to claim that Rakudo has this one correct.  The 
difference between the first and second examples above is that in 
the scalar variable example, the $a variable passed to infix:<~~>
contains the regex sub itself, whereas in the first example the
a regex is being invoked as a 0-argument listop prior to calling
the smart match.

In other words, the correct syntax is to use &a, as in:

    $ ./parrot perl6.pbc -e 'regex a { b }; say "b" ~~ &a;'
    b

By way of analogy:

    sub foo($x) { $x eq 'b' }

    say "b" ~~ foo;         # wrong, sub foo called as 0-arg listop
    say "b" ~~ &foo;        # right, sub foo passed to infix:<~~>

Pm

Reply via email to