Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Perl sigils

Name: Anonymous 2011-02-01 10:46

Why does Perl use sigils ($, @, %) to distinguish between scalar, array and hash variables? Python can live just fine without it, so what are advantages to have them? Disadvantages are clear, code looks fucking messy.

Perl 6 was an opportunity to ditch them, but they're still there.

Name: Anonymous 2011-02-01 10:53

>>1
In Perl 6, they are prefix operators.

Name: Anonymous 2011-02-01 10:55

>>2
What does it actually change?

Name: Anonymous 2011-02-01 10:56

>>3
Think about CL's #' reader macro.

Name: Anonymous 2011-02-01 11:38

>>1
Python isn't Perl 6. There are a lot of reasons, primarily context since sigils drive DWIM a lot of the time.

>>2
Not really:
$(<a b c>) # prefix $ evaluates -> ("a", "b", "c")
sub prefix:<$> ($a) { Mu } # define prefix $, returns Mu
my $a = 'foo'; # declaration and assignment 'foo'; unaltered behaviour
$(<a b c>); # returns Mu


Sigils are part of the term, not an operator on the term. Despite appearances above, the contextualizer behaviour of these symbols is not implemented in terms of operators:

$(<a b c>) # evaluates to ("a", "b", "c")
$<a b c>   # evaluates to (Any(), Any(), Any())
+<a b c>   # evaluates to 3


It just happens that when $ is defined as an op in Rakudo the operator shadows the term behaviour.

Name: Anonymous 2011-02-02 23:36

Name: tray 2012-03-16 16:18

flagStuff|=1;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List