Content deleted Content added
→Differences to Anonymous Classes: "different from" not "different to" |
→Clojure: lang="clojure" |
||
Line 1,213:
====Clojure====
[[Clojure]] supports anonymous functions through the "fn" special form:
<syntaxhighlight lang="
(fn [x] (+ x 3))
</syntaxhighlight>
There is also a reader syntax to define a lambda:
<syntaxhighlight lang="
#(+ % %2%3) ; Defines an anonymous function that takes three arguments and sums them.
</syntaxhighlight>
Like Scheme, Clojure's "named functions" are simply syntactic sugar for lambdas bound to names:
<syntaxhighlight lang="
(defn func [arg] (+ 3 arg))
</syntaxhighlight>
expands to:
<syntaxhighlight lang="
(def func (fn [arg] (+ 3 arg)))
</syntaxhighlight>
|