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 12:48
Subject:
Re: A complete design for := (bind)
Message ID:
20090825194841.GB12655@tytlal.topaz.cx
On Fri, Aug 21, 2009 at 07:37:05AM -0400, David Golden wrote:
> Is @b or *@b likely to be the more common case?  If *@b, then I'd
> rather see those as \@b and @b, respectively so the common case is
> most like the flattening Perl 5 syntax we know today.

I'm somewhat sympathetic to the POV that introducing Perl 6 flattening
semantics and punctuation is a poor fit in Perl 5, which has opposite
defaults [most of the time].

There are two competing memes in this field: Perl 5 prototypes (that exist),
and lvalue refs (proposed long ago).

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

Good: this isn't as ugly as I expected, and kinda looks like what it does.
Bad: It means that the backslash here:

    :(\$a) := ...

is either illegal or useless -- an unfortunate situation, and a warning sign
of error, but perhaps tolerable.


Alternate universe:

If we were to discard Perl 6 as a syntactic model and take only its useful
semantics, we could start with a proposal I made long ago but didn't work
all the kinks out of: lvalue refs.  All of the below, with one exception[1],
are fairly straightforward semantic extensions to Perl 5, and their meanings
(if not implementations :-)) should be clear:

   \$a = \$b;

   (\@a, \@b) = (\@c, \@d);

   \my($self, %args) = \(@_);

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.

  [1] The unstraightforward part of the extension is that using \(@a) or
      \(%a) as an lvalue would erase existing contents of @a or %a; or if
      not that, would at the very least stretch them if they are too small.
      Currently, nothing you can do with \(@a) alters the size of @a.


> I also don't terribly like :() syntax because I find it hard to skim.

I'm sorry, but "that's too much punctuation" is not a credible sentiment
from a Perl 5 programmer.  :-,


> >  :($a is ro) := ...
> >  :($a is copy) := ...
> 
> I don't like overloading "is" any more than it is already.

I'm sorry, but "I have to be aware of context" is not a credible sentiment
from a Perl 5 programmer, either.  :-,


>     bind(@a) := @x;

In fairness, that's pretty.
-- 
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