Why there is a "nil" at the end of output in clojure -
i wondering why there "nil" @ end of output in clojure. here code:
(defn foo [x &argu] (print x &argu))
and other question "&argu" mean here? variadic argument or something? thank much!
the repl (or whatever execution environment using) lets know output of evaluation of code. have written function not return anything. in such cases nil
returned convention. nil
clojure's marker nothing/null
. code doing printing - 'side effect'.
it important note nil
proper value in clojure. in contrast languages won't let compare undefined/unknown
value proper value - doing generate exception.
normally there's space, [x & argu]
. matters - please put space in code , try again. means function takes 1 or more parameters. quite correct in saying 'varadic'.
most languages have concepts of 'nil' , 'varadic arguments'. because clojure functional language whole thinking around 'only returning' functions becomes quite important. prioritising not having side effects in code makes easier reason about.
this function changed little:
(defn foo [x & argu] (println x argu))
and example usage in repl:
=> (foo 3 "hello" "how" "are" "you?") 3 (hello how you?) nil
see how inside function argu
has become list
.
Comments
Post a Comment