Syntax...
Vladimir Kirichenko
vladimir.kirichenko at gmail.com
Sat Nov 21 12:24:02 PST 2009
Neal Gafter wrote:
> Vladimir-
>
> We've been carefully avoiding keywords up to now, but I agree using
> keywords could result in more natural-reading programs. The problem is
> the risk of breaking existing programs. However, that is somewhat less
We survived "enum" I'm pretty sure "fun" is survivable too. Mostly
because of the same reasons - enum were used to implement ad-hoc enums
and "fun" most likely used with ad-hoc lambdas.
> severe now that there is a syntax for "exotic" identifiers. In JDK7 a
> keyword can still be used as an identifier by using the exotic
> identifier escape syntax. So the breakage is not as bad as it would
> have been earlier. It might be possible to use context-sensitive
> keywords, too.
>
> I would probably want to use something like 'fun' in place of '#' for
> function types, and 'lambda' or 'fun' in place of '#' for lambda
> expressions.
>
> fun int(int) plus1 = lambda (int x) x+1;
>
> I also prefer the result type on the right-hand-side of a function
> types, but somepeople seem to have trouble with that:
>
> fun (int)->int plus1 = lambda (int x) x+1;
I also like currying-like syntax, but made my proposal looking back to
those somepeople :) But it's understandable (int)->int looks alien in Java.
> This latter formulation is neater-looking when there are exceptions in
> the function type. For example, this
>
> fun int(int) throws Exception plus1 = lambda (int x) x+1;
>
> reads less well to me than this
>
> fun (int) throws Exception ->int plus1 = lambda (int x) x+1;
Putting identifier in the type declaration (like regular method) was
chasing two rabbits:
1. As a preparation for short form (EBNF.3) to remove duplicate type
declaration.
fun int increment(int x) => x + 1;
instead of
fun int (int) increment = fun int (int x) => x + 1;
notice double type declaration here.
2. Thinking about somepeople who used to see:
int increment(int x) { return x + 1 };
compare to:
fun int increment(int x) => x + 1;
--
Best Regards,
Vladimir Kirichenko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url : http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091121/466c0bd8/attachment.bin
More information about the closures-dev
mailing list