Front page | perl.perl5.porters |
Postings from August 2009
Re: A complete design for := (bind)
Thread Previous
|
Thread Next
From:
Abigail
Date:
August 25, 2009 13:22
Subject:
Re: A complete design for := (bind)
Message ID:
20090825202158.GA8167@almanda
On Tue, Aug 25, 2009 at 12:48:41PM -0700, Chip Salzenberg wrote:
> 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) = \(@_);
The above are somewhat obvious. But it begs the question, what do the
following mean? Would it even be legal?
\$a = $b; # Runtime error if $b isn't a ref to a scalar?
\$a = \@a;
\@a = [@b];
I don't think we need another smartmatch-like table to figure out what
LHS ref vs RHS ref means.
I kind of like:
my ($a, @b, %c)
local ($a, @b, %c)
our ($a, @b, %c)
state ($a, @b, %c) # Yeah, if only it could do aggregates.
bind ($a, @b, %c)
> 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. :-,
I like a keyword because it acts a bit like my/local/our/state - but that's
because I'm assume it will have some lexical scoped effect. ':( )' has the
advantage it's currently not legal syntax (AFAIK), and hence wouldn't need
an 'use feature;' to enable it.
But I find the feature to useful and important to spend too much time on
bikeshedding the syntax.
>
>
> > > :($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. :-,
That I fully agree with.
> > bind(@a) := @x;
>
> In fairness, that's pretty.
Yes.
Thread Previous
|
Thread Next