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

Re: A complete design for := (bind)

Thread Previous | Thread Next
From:
Chip Salzenberg
Date:
August 25, 2009 15:46
Subject:
Re: A complete design for := (bind)
Message ID:
20090825224603.GI12655@tytlal.topaz.cx
On Tue, Aug 25, 2009 at 06:22:41PM -0400, David Golden wrote:
> On Tue, Aug 25, 2009 at 3:48 PM, Chip Salzenberg<chip@pobox.com> wrote:
> > The existing Perl 5 prototype syntax spells concepts *similar* to flatten
> > and unflatten as @ and \@.  Just changing the bind syntax in that fashion,
> > one ends up with:
> >
> >    :($a, \@b, \%c) := ...   # should have 3 elements on RHS
> >    :($a,  @b,  %c) := ...   # @b ends up with N elements, %c ends up empty
> 
> I like this approach.  \$a could just warn, but see below.
> 
> > But where does one put "ro", "rw", or "copy" in this?  And what becomes the
> > syntactic marker to allow parsing new keywords in the first place?  And will
> > the resulting function prototypes be readable enough to use?  One wonders.
> 
> I get the sense that you're wanting to use the exact same syntax in
> function signatures as in code.

Well, sure.  If nothing else, it greatly simplifies instruction, and fails
to induce bugs when pulling signatures down into the code.  For example,
ignoring the 'my' issue, compare this wrapper-ish use case:

# before:
   sub foo (STUFF) { ... }
# after:
   sub foo {
      return if $AVOID_FOO;
      :(STUFF) := @_;
      ...

Keeping consistency in these cases is a goal I'm loathe to give up on.  But
it isn't a hard-and-fast requirement.

>     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.

>     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.
-- 
Chip Salzenberg

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