Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Should perl implement ,= or maybe overload .= (array context)

by theorbtwo (Prior)
on Aug 23, 2006 at 17:41 UTC ( #569149=note: print w/replies, xml ) Need Help??

in reply to Should perl implement ,= or maybe overload .= (array context)

To me, making .= do array concat seems rather off, for similar reasons to + not doing string concat. It's just not the right operator for the job. ,= is rather more interesting, but I don't really see a reason to introduce it; push @foo, @bar works just like you'd propose @foo ,= @bar to do.

Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Should perl implement ,= or maybe overload .= (array context)
by EvanCarroll (Chaplain) on Aug 23, 2006 at 18:47 UTC

    I agree fully with the example on '+', and '.' operators and that's why I thought ,= was more consistent with perl philosophy; but favoring a function'al approach rather than an operator approach for arrays seems more consistent with PHP a la array_new. As a side note though the analogy doesn't hold entirely true, perl -e'print "4 foo"+"1"' will demonstrate a purpose for +'ing two strings.

    I like '.=' more because it is clear what it should do in either context, and i don't really see a need for a ',='. Either operator would have a lower level of precedence too.

    Evan Carroll
      We've debated adding ,= to Perl 6, but so far have decided it would too easy to confuse with the .= operator visually. I suppose we could add ,= just for completeness and then come back in six months and deprecate anyone who is using it. :-)

      As for unifying with the .= operator, that wouldn't work at all in Perl 6 because we've taken over dot for method calls, and .= already indicates that you want to turn a non-mutating method call into a mutating method call. The append operator in Perl 6 is the ~=, but in Perl 6 the ~ character has very strong implications of stringification, and we wouldn't want to break that.

      All that being said, it'd be trivial for you to add your own ,= operator to Perl 6, and that's probably where we should leave it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://569149]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2017-06-25 05:41 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (564 votes). Check out past polls.