Carson Gross
Posts: 153
Nickname: cgross
Registered: Oct, 2006
|
|
Re: Inner Classes or Closures
|
Posted: Oct 18, 2006 2:11 AM
|
|
> The problem is that: > > each list, \elt -> sum += elt; ;
>
> Has two expressions in it and hence needs the two > semicolons; one expression is the whole thing, the second > is the lamda expression. You can't arbitrarily change the > parser, not because you don't own it but because it must > be able to parse old and new code, and I think this > is one of the cases where you can't change. Consider the > following that shows only one semicolon: > > method \x -> Type local = new Type( x ),
> x ), argumentOrLocal;
>
> What is this, it could be a method with two arguments, the > first a lamda expression. But it could also be a method > with one argument and a lamda expression that declares two > variables. The example should be: > > for two arguments
> method \x -> Type local = new Type( x );, argument2;
> or for two locals
> method \x -> SomeType local = new Type( x ), local2;;
>
I grow frustrated by this thread.
As I said previously, there are two very simple cases: either the closure body is a simple expression, in which case no enclosing syntax is needed, or it is a statement list, in which case you must wrap it in {}'s to delimit the body. Please, for the love of our Savior, no double semicolons. They are stark, raving, utter syntactic lunacy.
I really have no idea what imagined parsing problem you are talking about in the code above, but let me attempt a response:
method(\x-> Type local = new Type(x), argument2); //two args, simple as pie.
//Look! A comma separates arguments! And, as luck would have it, that
//is exactly how the java parser already works! No work!
method(\x -> { Type local = new Type(x), local2 } ) // one single closure arg
//Hey, look at that. Multi-expression/statement closure bodies are enclosed
// in curlies, just like good old method bodies. It's almost... consistent!
This is simple parsing stuff. We *have* the technology.
_shrug_ I'm just a simple cave man.
Cheers, Carson
|
|