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 21, 2009 04:37
Subject:
Re: A complete design for := (bind)
Message ID:
5d4beb40908210437l6c6a37fbp731350a1286cef3b@mail.gmail.com
On Fri, Aug 21, 2009 at 1:44 AM, Chip Salzenberg<chip@pobox.com> wrote:
> I believe this is a basically sound design, which we can follow fairly
> closely in parts (and transpose liberally in others).  This is my plan to
> bring both the mountain and Muhammad to a mutually agreed rendezvous.

My general reaction is "I get it" and, no offense, "god, that's ugly".

>   :($a, @b, %c) := ...
>
> expects three things on the RHS: a scalar (somehow), an array (somehow), and
> a hash (somehow).  In contrast,
>
>   :($a, *@b, *%c) := ...

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 also don't terribly like :() syntax because I find it hard to skim.
If this isn't a common case because these will be used in signatures
mostly, could it not be done with an explicit keyword instead?

    bind( $a, @b, %c ) :=

In such a case, could the ":=" be dropped and replaced with "="?  Or
could ":=" and variations be the way you designate ro or copies?


>   :($a is ro) := ...
>
> is a readonly bind, and
>
>   :($a is copy) := ...

I don't like overloading "is" any more than it is already.  Do we
really want "is ro" meaning one thing if Moose/etc/ is loaded, means
another if in :() and so on?  Too many special cases and context
dependent syntax makes it harder to teach, harder to skim and harder
to explain.

> Let us begin with the simplest solution that will work: Take as the RHS of :=
> a list of references to values of appropriate types.[1]  Perl 5 has adequate,
> if slightly clunky, syntax to do what's needed here.  For example, to bind
> arrays per se:
>
>   :(@a, @b, @c) := (\@x, \@y, \@z);
>
> Meanwhile, to bind array elements rather than whole arrays:
>
>   :(@a) := \(@x);

I get the first, but per my example above would rather see it as

    bind(\@a, \@b, \@c) := (\@x, \@y, \@z);

I don't understand why the second can't just be this (in my version
where @b is flattening and \@ is unit):

    bind(@a) := @x;

That has the nice property of making the most common case (I think)
explainable this way:

   sub foo(@args) { ... }

   # equivalent to

   sub foo {
       bind @args := @_;  # vs. "my @args = @_"
   }

That's easy to read and easy to teach.

> WHAT ABOUT THE REALLY SIMPLE BIND SYNTAX THAT I ALREADY IMPLEMENTED?
>
> I see no need for it.  It doesn't give us any substantial convenience; Occam
> suggests that it should go unless it can defend itself; and while binding
> will be very frequent, the explicit := operator will be quite rare.  Saving a
> few parentheses isn't worth the effort.

I disagree, as you've seen above.  If I had to sum up my view, I want
-OReadability.  I appreciate that you've worked through the semantics
for LHS and RHS, but I think the syntactic direction is wrong for Perl
5.  (E.g. I'd like to combat the "line noise" meme, not fuel it.)

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