1

I have:

(defn my-add [a b]
   "takes two numbers and adds them together"
   (+ a b))

this function works as expected:

(my-add 3 4) => 7

but when I do:

(doc my-add)

all I get is:

user/my-add
([a b])
nil

Whereas if I do 'doc' on a clojure/core function:

(doc str)

I get all the information I would expect, including the text:

clojure.core/str
([] [x] [x & ys])
With no args, returns the empty string. With one arg x .....[etc]

Why won't my user-defined function with document text also display? Thanks

1 Answer 1

3

Yes. You have the docstring in the fn body.

Try:

(defn my-add
  "takes two numbers and adds them together"
  [a b]
  (+ a b))
3
  • Thanks! I have also seen in a map placed after the doc string such as {:added 1.6 :author "John"}. How do I then access those from the (doc) function?
    – Zuriar
    Nov 6, 2014 at 16:41
  • @user3231690 those maps are metadata maps attached to the var. (meta #'clojure.core/map)
    – Kyle
    Nov 6, 2014 at 16:51
  • I see, so how can I get at them?
    – Zuriar
    Nov 6, 2014 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.