Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

[Perl6] Small 6 discoveries V, Sigils

by holli (Monsignor)
on Oct 08, 2017 at 23:02 UTC ( #1200958=perlmeditation: print w/replies, xml ) Need Help??

Some people like sigils. Some people don't. In Perl 6 you don't have to use them (as much).
my $x = 1; say $x; my \y = 1; say y; my @x = 1, 2; say @x; my \y = @ = 1, 2; say y; # also works with signatures sub foo(\x) { say x }; foo(1);
However you can't use sigilless attributes
class ThisExplodes { has \.y; #doesnt work has \y; #neiter does this }
You can use this for example to distinguish normal variables from ones in closures, or lexicals from function arguments or whatever. Or maybe you event want to get rid of all sigils where possible.

The choice is yours.

Sigilless variables do not create containers and are always immutable after initialization. They are therefore not a simple replacement with different visuals.

Edit: Fixed typo as hinted by NetWallah


You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re: [Perl6] Small 6 discoveries V, Sigils
by Laurent_R (Canon) on Oct 09, 2017 at 06:27 UTC
    I certainly don't want to get rid of sigils.

    In the proprietary programming language that I am using the most frequently after Perl, all variable names start with with a # character. Then, I am also doing quite a bit of shell programming, where variables start with $ (when you use hem).

    So, when I am using other programming languages su as C, Python or Scala, I have trouble telling variables from other identifiers. Sigils are so useful for me to know at first sight what kind of a beast I'm dealing with! I have almost come to the feeling that sigil-less programming languages are somewhat crippled. ;-)

      I agree with Laurent. And I could do with more sigil, which is more controversial. As much I would like to get rid of the as a French currency, I would like to have it as sigil for types that are Associative, Positional and Scalar. Many kinds of tree nodes could have that property. In Perl 6, a match acts like it has these properties but can't advertise it with .^roles (see below). $/ would be written as /. Ironically, a non match is Nil and not Match. And one successful match value cannot be used as an invocant to .^roles :
      'a' ~~ /a/; say $/.^roles OUTPUT: (exit code 1) Unexpected named argument 'transitive' passed

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1200958]
Approved by beech
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2018-07-23 12:18 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (465 votes). Check out past polls.