Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Perl6: S2 identifier and $ special var questions

by rir (Vicar)
on Sep 14, 2011 at 15:26 UTC ( #925931=perlquestion: print w/replies, xml ) Need Help??
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,

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:
    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,

        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://925931]
Approved by toolic
Front-paged by toolic
[choroba]: Good morning!
[Corion]: I hope you had a good weekend!
[marto]: jetlag has really done a number on the kids, it's been a tough week
choroba played with the band on Saturday, so Sunday was very sleepy
[choroba]: managed to release Syntax::Construct with 5.28 support in the night, though
[Corion]: choroba: Whee ;)
[Corion]: marto: Ouch - I would've thought that kids adapt much better, but that's obviously not the case...
[marto]: well, their mother let them sleep till 15:00 & 12:00 last week, which didn't help them adjust :P
[Corion]: I was "productive" over the weekend in the sense that I revived my old "Perlmonks on SQLite" code, which likely means I can get a test instance back up running on my webhost. Small steps :)
[Corion]: marto: Ow, no, that doesn't help at all :)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2018-06-25 08:35 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.