develooper Front page | perl.perl5.porters | Postings from September 2009

Re: A complete design for := (bind)

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
September 3, 2009 14:32
Subject:
Re: A complete design for := (bind)
Message ID:
20090903213134.GA24487@klangraum.plasmasturm.org
* Ben Morrow <ben@morrow.me.uk> [2009-08-29 15:25]:
> First: I don't like the ro-alias default at all. I would much
> prefer a cow-alias

Is there any user-visible difference between a copy and a COW
alias? If not, there’s no such thing as a COW alias as far as
the user is concerned… it’s just an implementation detail.

> for one thing, it's not at all clear how 'deep' the
> readonlyness should go.

The only sane option IMO is that it be completely shallow.
I mean, how is that question different from asking how deeply
a copy should copy? Seems to me the answer should be the same
in both cases, for the same reasons.

>     sub foo (@a) {      # expects scalars, creates ro aliases
>     sub foo (\@a) {     # expects array, creates ro alias
>     sub foo (!@a) {     # expects scalars, creates rw aliases
>     sub foo (!\@a) {    # expects array, creates rw alias
>     sub foo (=@a) {     # expects scalars, creates copies
>     sub foo (=\@a) {    # expects array, creates (1-level deep) copy

Like the :() proposal I find this is too much punctuation.
I would prefer a slightly more keywordy notation, maybe (to
follow existing precedent in Perl) something like attribute
synax:

      sub foo ( @a) {         # expects scalars, creates ro aliases
      sub foo (\@a) {         # expects array, creates ro alias
      sub foo ( @a : rw) {    # expects scalars, creates rw aliases
      sub foo (\@a : rw) {    # expects array, creates rw alias
      sub foo ( @a : copy) {  # expects scalars, creates copies
      sub foo (\@a : copy) {  # expects array, creates (1-level deep) copy

Be a bit shorter and lighter-looking than `is` and also leaves
whitespace style up to the user (something Abigail will surely
appreciate :-) ).

> We already have
>
>     state $x = 4;
>
> which isn't in any way an ordinary assignment

Good point.

> so what's wrong with
>
>     alias $x = $y;
>
> which has the advantage of being compatible with Data::Alias in
> simple cases?

Yeah, I like this.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | Thread Next


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