This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-31
Channels
- # admin-announcements (1)
- # beginners (16)
- # boot (25)
- # braid-chat (7)
- # cider (4)
- # cljsfiddle (6)
- # cljsrn (1)
- # clojure (256)
- # clojure-austin (4)
- # clojure-ireland (1)
- # clojure-poland (15)
- # clojure-russia (80)
- # clojure-uk (2)
- # clojurescript (30)
- # core-async (14)
- # core-typed (3)
- # cursive (35)
- # datomic (1)
- # editors (28)
- # hoplon (32)
- # immutant (1)
- # jobs (8)
- # jobs-discuss (1)
- # juxt (6)
- # leiningen (8)
- # liberator (7)
- # off-topic (16)
- # om (69)
- # onyx (38)
- # re-frame (10)
- # spacemacs (1)
- # untangled (117)
how would I get the full namespace qualified name of a function?
for clojure tools namespace they demonstrate a refresh function
(refresh :after ‘dev/start))
but they know the name of the namespace the function comes from. what if you would like to generalize it so you can use arbitrary functions and not have to worry about where it came frommy copy of Clojure for the Brave and True arrived today thx @nonrecursive
I'm reading Clojure for the Brave and True and I'm confused with the first 4 lines of code:
(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!
http://www.braveclojure.com/do-things/#loop
Could someone explain them?[]
says what to do when no argument is passed to the function (it calls itself, this time with zero as the argument), and [iteration]
is what to do when an argument is passed. That help?
@mkaschenko: clojure allows you to have multi arity functions
if you want a function that returns 0 if no arguments were passed and 5 if one argument was passed you could right this
(defn my-func
([] 0)
([anything-other-than-nothing] 5))
and a function can call itself, just provide more/less arguments as shown in the example above.
this is really useful when you want to expose a nice easy to use function to others, but behind the scenes you might need an accumulator or some other thing which is irrelevant to the consumer of the function