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

Re: A complete design for := (bind)

Thread Previous | Thread Next
From:
David Golden
Date:
August 25, 2009 16:31
Subject:
Re: A complete design for := (bind)
Message ID:
5d4beb40908251630o60d5dcbdy83d7d0604adddf9b@mail.gmail.com
On Tue, Aug 25, 2009 at 6:46 PM, Chip Salzenberg<chip@pobox.com> wrote:
>>     sub foo(\$a, \@b) { ... } # aliasing
>>     sub foo($a, @b) {... } # copying
>
> You've forgotten, I think, that so far \@b vs. @b is our best Perl5-ish way
> to specify flatten or non-flatten.  Alias rw vs. alias ro vs. copy is a
> separate dimension.  The default case in Perl 6 is read-only aliasing, and I
> think that's a very good default: it is highly (if not perfectly) efficient,
> and also safe.  It would be bad Huffmanizing to require decoration to get it.

I agree on the decoration point.  So you want this, with all aliases
being read-only:

    sub foo( $a, @b, %c ) { ... }
    # $a is an alias, @b contains aliases to remaining arguments, %c is empty

    sub foo( $a, \@b, %c ) { ... }
    # $a is an alias, @b is an alias to an array argument, values in
%c are aliases

That syntax seems clean if read-only aliases are the most likely use
case.  I'm not sure I like the idea of introducing read-only by
default just because it's so different from how things work today,
where @_ is a read-write alias.  On the other hand, it's different
enough that it should be a short learning curve.

>>     sub foo(\$a is ro, \@b is ro) { ... } # readonly alias via traits
>>     sub foo(:$a, :@b) { ... } # readonly alias via punctuation (with
>> '\' unnecessary given context of ':')
>
> ("Rule #1 of language design: Everybody wants the colon." - Larry)
>
> Seriously, though, if the colon is going to appear in function signatures
> I think it should be more the "self" marker.  Punctuation is harder to
> extend, too; witness the value of the attribute list.

I don't terribly mind traits in a signature.  I do mind them in the
body of the code since they look like bareword function calls but
aren't (in this context anyway).  I'd be annoyed to see "is rw" in
Moose declarations and in signatures and elsewhere in code and have
them executing through very different mechanisms.  That just doesn't
feel like good design to me.  But other than more punctuation, colon
or otherwise, in the signature, I don't see a decent alternative
option.

-- David

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