-1
user=> (defn make-list [] '(1 2 3))
#'user/make-list
user=> (defn get-list [] (map #(str "foo" % ) make-list))
#'user/get-list
user=> (get-list)
IllegalArgumentException Don't know how to create ISeq from: user$make-list  clojure.lang.RT.seqFrom (RT.java:505)
user=> (defn get-list [] (let [ml (make-list)] (map #(str "foo" % ) ml) ))
#'user/get-list
user=> (get-list)
("foo1" "foo2" "foo3")

Why can the value from defn not be accessed in the same way from the BODY of a function as it can from the LET clause?

Mond Raymond
  • 320
  • 1
  • 4
  • 9
  • 2
    makeList is a function. You can not map over a function. Try (map #(str "foo" %) (makeList)) instead. – Jonas Jun 01 '14 at 20:04
  • such a dumb question, I am tempted to delete it. Have decided to leave it as a testament to my idiocy and as advice to others who mess up like this – Mond Raymond Sep 18 '14 at 14:52

1 Answers1

3

defn declares a function so you need to invoke it in order to get its result:

(defn make-list [] '(1 2 3))
(defn get-list [] (map #(str "foo" % ) (make-list)))
(get-list)

;; ("foo1" "foo2" "foo3")

But since your makeList function doesn't do anything but return a list, you can use def instead as it simply declares a var:

(def make-list '(1 2 3))
(defn get-list [] (map #(str "foo" % ) make-list))
(get-list)

;;("foo1" "foo2" "foo3")

Lastly, use kebab-case instead of camelCase for function and var names in Clojure. That's the convention unless you're declaring Protocols or Types.

Community
  • 1
  • 1
leonardoborges
  • 5,579
  • 1
  • 24
  • 26