Friday, September 6, 2013

How to find what is in the Clojure libraries with REPL

First, load the clojure.repl lib

First you need to load the clojure.repl library. You should be able to do this by typing:
(use 'clojure.repl)
If this fails then see this post

What functions are available in a library

For example, what functions are in the repo library:
(dir clojure.repl)

Lookup documentation for a function

If you want to lookup the documentation for "when" for example, type:
(doc when)

Find definition by matching it's name

If we want to find all the definitions that contain the word "map" in their names then use apropos.
(apropos "map")

Find all documentation that contain a word

If you want to look up all definitions that have the word "stream" in it's documentation then type:
(find-doc "stream")

Look at the source code of a function

If you want to see the code for a function, yours or the Clojure functions.
To find the source code of the defn function, type:
(source defn)


you can visit the Clojure cheat-sheet at or you can query via the REPL.

No comments:

Post a Comment