On Sun, Jul 10, 2011 at 5:42 PM, octopusgrabbus
<[email protected]> wrote:
> From Clojure api for max
>
> (defn max
> "Returns the greatest of the nums."
> {:added "1.0"}
> ([x] x)
> ([x y] (if (> x y) x y))
> ([x y & more]
> (reduce max (max x y) more)))
>
> Question 1: Why can y be introduced as a local binding without a let?
Local bindings can be introduced by three special forms, fn*, let*,
and loop*, and by any macro that expands to one of these, including
but by no means limited to fn, let, loop, defn, and with-open.
In this case the two y bindings are introduced by fn* via the defn
macro as function parameter bindings.
> Question 2: What is the map {:added "1.0"} doing?
Adding arbitrary metadata key/value pairs to the function. The defn
macro will apply it to the symbol 'max and the def special form that
it expands into will propagate it to the Var clojure.core/max:
=> (meta #'clojure.core/max)
{:ns #<Namespace clojure.core>, :name max, :file "clojure/core.clj",
:line 912, :arglists ([x] [x y] [x y & more]), :added "1.0", :doc
"Returns the greatest of the nums."}
The defn macro will also apply it to the actual function object:
=> (meta clojure.core/max)
{:ns #<Namespace clojure.core>, :name max, :file "clojure/core.clj",
:line 912, :arglists ([x] [x y] [x y & more]), :added "1.0", :doc
"Returns the greatest of the nums."}
--
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en