Darren Duncan
Mon, 14 May 2007 17:28:29 -0700
At 5:00 PM -0700 5/14/07, Darren Duncan wrote:
On the other hand, unless this steps on something, I could suggest dropping the @ and % anyway, so we have $array and $hash, and then we could instead use the @ and % sigils as a prefix to indicate in that case that we want them to copy by value. For example:my $foo = [23, 434, 6]; my $bar; $bar = $foo; # copy by reference @$bar = @$foo; # copy by valueActually, I think that would be a vast improvement, as we could then use the @ prefix with any collection type as short-hand to say that = is copy by value.
As a follow-up or clarification of what I just said, here is a proposal ... Variables of all types have $ sigils.The semantics of $foo = $bar are unchanged; usually $foo and $bar point to the same container after the assignment, afaik.
Prefixing a @ or % before a variable name indicates a syntactic short-hand for something concerning the variable.
On declaration, saying @$foo means the same as "Array $foo", and saying %$foo means the same as "Hash $foo", or some such. This works for my|our|has etc as well as parameter declarations. This is instead of declaring @foo or %foo.
On use in an expression, @$foo = @$bar indicates we want a copy by value or clone or shallow copy or whatever, and $foo and $bar point to different containers after the assignment; the semantics are like the current @foo = @bar.
Similarly, use eg @@$foo rather than @@foo as appropriate.With these changes, I see it making Perl more consistent in appropriate ways, and easier to use, and huffmanizing isn't worse.
Also, it means we can free up the @ and % rare ASCII symbols for other purposes in some situations.
I could also argue that the conception of @ meaning plural vs $ singular isn't really an absolute, since any value can be treated as either being a collection or being atomic under different circumstances.
-- Darren Duncan