develooper Front page | perl.perl6.language | Postings from April 2005

Re: is rw basically a null-op on objects/references?

Thread Previous
From:
Juerd
Date:
April 28, 2005 05:59
Subject:
Re: is rw basically a null-op on objects/references?
Message ID:
20050428125940.GS26732@c4.convolution.nl
Juerd skribis 2005-04-28 14:47 (+0200):
> Yes, because a pair is an object (reference), and it's not the .value
> that you're passing ro.

An example of what would go wrong:

    for %hash.pairs>>.value -> $value {
        $value = ...;
    }

But this will work:

    for %hash.pairs>>.value {
        $_ = ...;
    }

And this again won't:

    for %hash.pairs>>.value -> $_ {
        $_ = ...;
    }

This makes "upgrading" a block to use an explicit name a painful
experience if you happen to mutate its value, because you have to
specify 'is rw', which I'm sure will bite many people many times.

This is why I want <->, so that the default for

    for ... { ... }

can be

    for ... <-> $_ { ... }

rather than the unexpected

    for ... -> $_ is rw { ... }

so that $_ is the default, and no special default-magic for "is rw" is
needed. Of course, "<-> $_" and "-> $_" are 100% equal internally.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About