in reply to Perl6::Rules Rules

I'm guessing "oporm" is short for "optional plus or minus", but it took me a while to guess that. I'd suggest replacing it with:

rule sign { <[+-]> }
and using <sign>? instead of <oporm> in the other rules to improve readability.

The $num = $num + 0; ensures the returned result will be treated as a number if used in an ambiguous context, such as with a bitwise operator. So yes, if the is_* functions are documented to return a number it's helpful to do this.

I'd normally expect a function 'is_thing' to be asking a question that returns a boolean though, and to use it like:

if (is_fixed($string)) { ... it's a number ... }
and would usually name functions such as yours more like 'as_thing':
my $num = as_scino($string);

Hugo

Replies are listed 'Best First'.
Re^2: Perl6::Rules Rules
by duff (Parson) on Aug 04, 2004 at 14:34 UTC
    The $num = $num + 0; ensures the returned result will be treated as a number if used in an ambiguous context, such as with a bitwise operator. So yes, if the is_* functions are documented to return a number it's helpful to do this.

    Would that he were using a real Perl6, he could just use unary + on the return to force numeric context:

    return +$num;

    This would remove the extra, potentially confusing addition which IMHO is a good thing. /me waits for Perl6 with bated breath.

      And in Perl5, of course, you just write

      return 0 + $num;

      :-)

      Makeshifts last the longest.