http://qs1969.pair.com?node_id=882394


in reply to Perl 6 and Perl 5 parsing

Perl5's grammar is mutable too.
$ perl -E'sub f() { 0 } say f + 1;' 1 $ perl -E'sub f($) { 0 } say f + 1;' 0
$ perl -E'sub f { say $_[0]; } f { foo => "bar" };' HASH(0x816c158) $ perl -E'sub f(&) { say $_[0]; } f { foo => "bar" };' CODE(0x817bc80)
$ perl -E' $x = foo; say $x; sub foo { "sub" }' foo $ perl -E'sub foo; $x = foo; say $x; sub foo { "sub" }' sub

Update: Added an example to show that prototypes aren't the only source.

Replies are listed 'Best First'.
Re^2: Perl 6 and Perl 5 parsing
by TimToady (Parson) on Jan 14, 2011 at 21:01 UTC
    Interestingly, because Perl 5's mutability under sub declarations was so confusing to people; Perl 6's sub declarations never mutate the grammar. Apart from explicit macros or mixed-in grammar rules, the only thing that can change the grammar is a constant declaration, which declares a word that never takes arguments, much like a 0-ary sub in Perl 5. (Type declarations may be considered a specialized kind of constant declaration, where the constant being declared just happens to be a type.) In Perl 6, there are no barewords, so any unrecognized word is assumed to be a list operator that will be declared later in the same file.

    So while Perl 6's grammar is more mutable in theory; it is less frequently mutated by accident.

    Another interesting consequence of this decision is that the blocks supplied to map and grep are not a special syntax, so they require a comma. Likewise use of & in a sub signature does not change parsing. On the other hand, bare blocks are just anonymous closures in Perl 6, so they can be passed in any position, and are not restricted to the first argument as they are with Perl 5's & prototype.