--- Jason Foreman <threeve.org / gmail.com> wrote:

> I hadn't seen this particular variant posted in this thread
> yet. 
> Apologies if it was and I missed it.  I make no claims as to
> its ease
> of parsing or whatever, but it looks better than many of the
> other
> options to me.
> 
> 
> bar = { x, y=3, z=b|5 ->
>   x + y * z
> }
> 
> 
> I believe this is similar to the approach that Groovy [1]
> uses for its blocks.


A few of us (you, me, Florian) have suggested variants of this:

{ arg-list <delimiter> code }

You and Florian suggested the delimiter be "->".  I suggested
":"+spacing (to not confuse with symbols) or ;/newline if the
args were made mandatory.

I think any of these delimiters plus probably others could work
and look good.  The general form above is about the most
concise you can get and probably the best if workable.

The problem with this is 2 fold:

1. It can be difficult/impossible to differentiate a lambda vs.
a hash.  I'd prefer to change the hash syntax.

2. If the arg-list/delimiter is optional, it requires an
indeterminate amount of lookahead to determine whether the
lambda/block starts with an arg list or code.  A parser
solution to this is to initially treat the arg-list as code and
then if the delimiter is found (could be thought of as an
arg-list operator) in the first statement/expression where that
expression/statement can terminate, treat what is to the left
as the arg-list.  I think this should work because as far as I
see any valid arg-list (including defaults) also happens to be
a valid expression.  But, after the delimiter is found, the
parse tree for the arg-list would have to be cleaned up and
some extra syntax checking would be needed.  Kind of ugly, but
doable.




		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs