4 ms·
State of the (Java) Lambda
- RodgerTheGreat 16y agoWell, at the very least the new syntax is a tremendous improvement upon the previous proposals. (http://cr.openjdk.java.net/~mr/lambda/straw-man/ http://cr.openjdk.java.net/~mr/lambda/straw-man/) Compare the old #(int x)(x + x) To the new {x -> x + x} Much more consistent with the syntax of normal Java. Seems to be borrowing from C#.
- evilduck 16y agoI hadn't followed up on it since the previous proposal but....thank goodness. The pound-sign lambda annoyed me since other lambda capable languages use it to denote comments. It wasn't a dealbreaker, but it certainly was less than preferred.
- cabalamat 16y agoI agree. I know of no other language where a # is used to denote lambdas. I would prefer one of: 1. a keyword such as fn, fun, function, lambda. (Incidently, my language uses fn) 2. {...} are used to denote code blocks in many languages, including Java 3. -> or => are also used for functions in several languages (IIRC C# uses =>)
- Zak 16y ago# is used for lambda shorthand in Clojure. #(+ % %2) is shorthand for (fn [x y] (+ x y)).
- cabalamat 16y agoThat's a nice shorthand. AIUI, Arc uses [... _ ....] as a terse shorthand for closures, but can only deal with functions that take one argument that way -- though it would be simple to expand Arc so it could say [+ _ _2]. Now I've thought about it, I may add something similar as syntax in Unify: (tn + _ _2) (where tn stands for "terse function")
- shadowfox 16y agoIs it still part of Java 7 release?
- deleted 16y ago[deleted]
- navteniev 16y agoI find the use of "yield" a little strange. In Ruby yield, yields the execution to the block that was passed in as an argument to the method being invoked. In this proposal it would replace the "return" statement inside a lambda.
- warmfuzzykitten 16y agoIn other languages, yield is used for coroutine (continuation) return. Bad choice. There is actually no reason not to use return, or to disallow break and continue. These could all have the same meaning as they do in a SAM implemented with an inner class.
- jcdreads 16y agoInstead of {x -> x + 1} you could always run clojure on your existing production JVM and write #(+ % 1) to get the same effect.