On 11 July 2011 03:42, Luc Prefontaine wrote:
> Lets try to clear the confusion a bit here:
>
> (def max1 [x] x)
> (def max2 [x y] (if (> x y) x y))
> (def max3 ([x y & more] (reduce max (max x y) more)))
>
> The above a three different fns.
To be even more clear, the above should be:
(defn max1
On Sun, Jul 10, 2011 at 5:42 PM, octopusgrabbus
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 bind
Lets try to clear the confusion a bit here:
(def max1 [x] x)
(def max2 [x y] (if (> x y) x y))
(def max3 ([x y & more] (reduce max (max x y) more)))
The above a three different fns.
max1 has only the arg x.
max2 has only x and y
and max3 has x and y and maybe other arguments to select the maximu
On Sun, Jul 10, 2011 at 4:51 PM, octopusgrabbus
wrote:
> If the function is called with one argument, what Clojure language
> rule allows x to appear outside the vector brackets?
([x] x)
The x outside of the vector brackets is the value being returned.
So if max is called with only a single arg
I have another question about max. Is there an advantage if this were
re-written with repl?
On Jul 10, 7:18 pm, Jonathan Fischer Friberg
wrote:
> There's no interfaces, that's the function definition.
>
> define function max
> (defn max
>
> attach docstring
> "Returns the greatest of the nums."
>
If the function is called with one argument, what Clojure language
rule allows x to appear outside the vector brackets?
On Jul 10, 7:18 pm, Jonathan Fischer Friberg
wrote:
> There's no interfaces, that's the function definition.
>
> define function max
> (defn max
>
> attach docstring
> "Returns
There's no interfaces, that's the function definition.
define function max
(defn max
attach docstring
"Returns the greatest of the nums."
attach metadata
{:added "1.0"}
if max is called with one argument, use this function definition
([x] x)
if max is called with two arguments, use this functi
2) Meta data, max was introduced in V1.0
On Sun, 10 Jul 2011 14:44:16 -0700 (PDT)
octopusgrabbus wrote:
> For Question 1 this is an example of multiple interfaces. Got it.
>
> On Jul 10, 5:42 pm, octopusgrabbus wrote:
> > From Clojure api for max
> >
> > (defn max
> > "Returns the greatest o
For Question 1 this is an example of multiple interfaces. Got it.
On Jul 10, 5:42 pm, octopusgrabbus 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) mor