Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: Thoughts on some new operators for perl (6 or 7)

by Juerd (Abbot)
on Mar 10, 2004 at 14:26 UTC ( #335453=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Thoughts on some new operators for perl (6 or 7)
in thread Thoughts on some new operators for perl (6 or 7)

.= doesn't make sense for its new purpose

If you can't imagine a function for it, it automatically does not make sense?

It could very well become a mutator for objects. As $foo += 5 equals $foo = $foo + 5, $foo .= lc could equal $foo = $foo.lc. Especially for @foo.sort and @foo.=sort, this would be great to have.

I've been wanting mutating and non-mutating versions of builtins for a while now, and this seems to me a good way to do it.

See also Re: Re: What should be returned in scalar context?.

Does it make sense now?

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Comment on Re: Re: Re: Thoughts on some new operators for perl (6 or 7)
Select or Download Code
Re: Re: Re: Re: Thoughts on some new operators for perl (6 or 7)
by hardburn (Abbot) on Mar 10, 2004 at 14:58 UTC

    Sense, yes. But pulling the method and object apart like that is uglier than its worth, IMHO. If you want mutating on an object, than you should define method to work that way already.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      If you want mutating on an object, than you should define method to work that way already.

      No, that is exactly the opposite of what I want. That way you get again the mess that Perl 5 also has: some are mutating, some are not. I want everything to be non-mutating by default with some kind of modifier to make it mutating. This thread made me think of .= and I think it is a very good candidate, because it works much like the other op= operators: foo op= bar does the same as foo = foo op bar, but with possible optimizations.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        In practice, you're not going to get that, unless you convince every Perl programmer to lay out their class design so they respect the mutating/non-mutating idiom.

        Also, is it your habit to downvote every node you happen to disagree with?

        ----
        : () { :|:& };:

        Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335453]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (19)
As of 2014-08-27 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (239 votes), past polls