in reply to Re^2: Unifying namespaces of @name and $name to simplify dereferencing?
in thread Unifying namespaces of @name and $name to simplify dereferencing?
I'm not trying to eliminate list contextWell yes, that's not something I would suspect of you anyway ;-).
I actually didn't think the my $array = ["Hello", "World"]; print $array[0]; example through. It might work here because of the my, which means that $array isn't already linked to another array. But if you want to redefine the content of the array without breaking the link you have to write @array = (1..4);. Because $array = [1..4]; would link $array to a brand new array, or not be consistent with "normal perl" (and $ar = $br would either alias @ar to @br, or not lead to $ar == $br, or make $ar != \@ar). So in the end you're right, this doesn't make it easy to just pretend the @ sigil doesn't exist, and this doesn't work like the perl6 sigil invariance at all. I suppose it's fine if the option is scoped correctly :
my @outer; my $otter = [1..4]; { use autorefs; my $inner = [1..10]; print $inner[5]; # Neither $outer nor $otter[0] are legal } # @inner is obviously not allowed here
I haven't worked much with perl6, just done a few tests and mostly read about it. I'm sure the subject must have been covered many times but your meditation just made me realize the point of keeping the @ sigil when $a = 1..4; $a[0] and @a = 1..4; @a[0]; do the same thing, and what it changed for @a to be an array and $a to be an array ref if both where just going to be passed as a single argument anyway. That's because @a = 1..4; @b = @a is "equivalent" to $a = 1..4; @b = $a (@b is a clone of the array a) but not to $a = 1..4; $b = $a; or even @a = 1..4; $b = @a ($b is a ref to the array a).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Unifying namespaces of @name and $name to simplify dereferencing? (declaration of typed references)
by LanX (Saint) on Mar 27, 2016 at 17:05 UTC | |
by Eily (Monsignor) on Mar 27, 2016 at 20:20 UTC | |
by LanX (Saint) on Mar 27, 2016 at 20:49 UTC | |
by Eily (Monsignor) on Mar 28, 2016 at 12:17 UTC | |
by LanX (Saint) on Mar 27, 2016 at 21:21 UTC | |
by Eily (Monsignor) on Mar 28, 2016 at 12:23 UTC |