develooper Front page | perl.perl6.language | Postings from July 2005

Re: return() in pointy blocks

Thread Previous | Thread Next
From:
Larry Wall
Date:
July 4, 2005 11:32
Subject:
Re: return() in pointy blocks
Message ID:
20050704183235.GB25023@wall.org
On Mon, Jul 04, 2005 at 07:01:00PM +0200, "TSa (Thomas Sandlaß)" wrote:
: Larry Wall wrote:
: >On Wed, Jun 08, 2005 at 12:37:22PM +0200, "TSa (Thomas Sandlaß)" wrote:
: >: BTW, is -> on the 'symbolic unary' precedence level
: >: as its read-only companion \ ?.
: >
: >No, -> introduces a term that happens to consist of a formal signature
: >and a block.  There are no ordinary expressions involved until you
: >get inside the block.  (Or set a default on one of the parameters, to
: >the extent that those are ordinary expressions.)
: 
: So without a block there is a syntax error?
: 
:   $x = -> $y;

Yes.

: Or could this be understood as a short form of
: 
:   $x = -> { $y } # $y from outer scope

Could, but I'm prejudiced against implicit lexical scopes.  && and ||
and ??:: are okay as standard forms of indirect quotation, but natural
languages are notorious for getting into ambiguous situations with
that kind of laziness.  So that's one of the "features" I'm slow to
copy from human languages.  Curlies are already short, and in Perl
6 have the (almost) universal meaning of direct quotation of code.

: I still think the pointy looks really cute as a prefix operator
: for constructing rw refs. Especially if we use () to evaluate
: the blockref returned. For plain variable assignment this is
: not overly usefull because it amounts to the same as
: 
:   $x := $y;
: 
: but in lists it is quite nice
: 
:   %h = { foo, 'bar', blah, -> $y };
: 
: or not?
: 
:   %h = { foo => 'bar', blah => -> $y };

I don't think the semantics pass the Pooh test.   It's also confusing
syntactically.  What state is the parser supposed to be in when it
gets to the end of this:

    foo => 'bar', blah => -> $x, $y, $z

If the precedence of -> is list operator (and it needs to be to gobble
up pointy sub arguments), then you have to write one of

    foo => 'bar', blah => -> ($x), $y, $z
    foo => 'bar', blah => (-> $x), $y, $z

to limit it to the first argument, and you might as well have put some
curlies there.  We're not going to do arbitrary lookahead to find a {
to decide the precedence of -> on the fly.  That would be insane.

: hmm, can the following be interpreted as spoiling pair notation?
: 
:   %h = { :foo<bar>, :blah< -> $y> }; # would blah<-> $y> parse at all?

That won't parse.

: I think not because this works
: 
:   %h = { :foo<bar>, :blah{-> $y} };

That won't parse either.

Larry

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