On Sunday, September 4, 2016 at 4:58:34 PM UTC-4, Charlie wrote:
>
> I'm going through the Do Things: A Clojure Crash Course, and the following 
> example (in REPL) is presented:
>
> (defn recursive-printer
>   ([]
>      (recursive-printer 0))
>   ([iteration]
>      (println iteration)
>      (if (> iteration 3)
>        (println "Goodbye!")
>        (recursive-printer (inc iteration)))))(recursive-printer); => 
> Iteration 0; => Iteration 1; => Iteration 2; => Iteration 3; => Iteration 4; 
> => Goodbye!
>
>
> This works as expected, but I don't understand the syntax of the function 
> definition. Specifically: (defn recursive-printer ([] (recursive-printer 
> 0)). Isn't the parameter list supposed to be a vector [] not ([]...)? Also, 
> I don't see how [iteration] is resolved on the next line.
>
> Thanx for any help!
>
>
You may be familiar with function overloading in other languages, where one 
can define multiple functions with the same name as long as their 
signatures (parameter lists) are different. Clojure does not have types on 
its parameters, but can still support overloading as long as the arities 
(parameter counts) are different.

In other languages you might see:

(defn himom [] ..)
(defn himom [x] ...)
(defn himom [x y z] ...)


Come to think of it, maybe Clojure does that, too, (nooby myself) but the 
Clojure syntax for overloading I know puts each definition under the same 
defn, wrapping each in parens):

(defn himom
 ([] ..)
 ([x] ...)
 ([x y z] ...))

 hth,kt

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to