http://qs321.pair.com?node_id=925931

rir has asked for the wisdom of the Perl Monks concerning the following question:

Quoting Synopsis 2:
The $Package'var syntax is gone. Use $Package::var instead. (Note, however, that identifiers may now contain an apostrophe or hyphen if followed by an "idfirst" letter.)
idfirst means a unicode Alpha character (roughly equivalent to \w) and it seems that the Synopsis may be revised.

So this seems to allow these kind of declarations:

my $<-var>; our $<-v'a-r>; # line 76
In Rakudo Perl 6, version 2011.07 this doesn't work. Rakudo seems to accept any text, including an empty string, and these all declare the same $ and a second declarations give a diagnostic like:
> ===SORRY!=== > Redeclaration of symbol $ at line 76, near " = \"B\"; sa"

(Re: the spec):

Do I have the quotish syntax correct? Is there test code at which to look?

Is this meant to apply to my identifiers? Subroutine and method identfiers?

What is the rationale for this flexibility in identifiers? I can see how language design/evolution and interfacing with other languages may be enhanced, but I wonder if I am missing some intended utility.

Is there supposed to be a $ variable in any context?

Be well,
rir

Replies are listed 'Best First'.
Re: Perl6: S2 identifier and $ special var questions
by TimToady (Parson) on Sep 14, 2011 at 16:56 UTC
    The correct response is provided by niecza, which says:
    ===SORRY!===
    Cannot declare a match variable at (eval) line 1
Re: Perl6: S2 identifier and $ special var questions
by PrakashK (Pilgrim) on Sep 14, 2011 at 15:56 UTC

    In S02 synopsis, section "Names and Variables", I see:

    $<foo> match variable, short for $/{'foo'}

    So, when you say my $<-var>;, you are actually initializing the key -var of the hash $/.

    Here's what I see in recent rakudo:

    >> perl6 -v This is Rakudo Perl 6, version 2011.07-2-g1b7dd12 built on parrot 3.6. +0 RELEASE_3_6_0 >> perl6 > my $<-var> = 42 42 > $/ -var 42 > $/.WHAT Hash()
      Thanks, the code is explained.

      How would I declare and use $MyClass::-O'malley's as indicated by the quoted spec?

      Be well,
      rir

        You may not start an identifier with - like that; hyphens and apostrophes are only allowed internally.

        In theory one can declare or use any name you like using Perl 6's explicit symbolic ref notation:

        my $::("-O'Malley's") = 42; say $::("-O'Malley's");
        However, neither implementation does constant folding well enough yet to recognize these as a static variable names.