Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use clojure doc function?

I'm just starting with Clojure and can't access to the doc function.

I'm using clojure 1.3 with emacs24 and swank-clojure.

user> *clojure-version* {:major 1, :minor 3, :incremental 0, :qualifier nil} 

But when I try:

(doc doc) 

I get:

Unable to resolve symbol: doc in this context [Thrown class java.lang.RuntimeException] 

I've read Why does REPL treat clojure.core/doc as a var? and as suggested:

(clojure.repl/doc doc) 

But then, I receive:

clojure.repl [Thrown class java.lang.ClassNotFoundException] 

It seems I am not "importing" the usual namespaces, but really doesn't know how to do it.

Thanks.

UPDATE

Using clojure from java (java -jar ...) it works well, so it's a problem with the emacs setup.

like image 736
zaforas Avatar asked Nov 30 '11 20:11

zaforas


People also ask

How to document clojure code?

Clojure functions are documented by adding a string to the function definition, after the function name. This is referred to as the doc string. def bindings can also be documented to provide context to the data the name is bound to.

What is def Clojure?

def is a special form that associates a symbol (x) in the current namespace with a value (7). This linkage is called a var . In most actual Clojure code, vars should refer to either a constant value or a function, but it's common to define and re-define them for convenience when working at the REPL.

What is a Clojure REPL?

A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.


1 Answers

You need to grab the clojure.repl namespace one way or another:

From the REPL

user> (use 'clojure.repl) user> (doc doc) 

or in your program

(ns foobar   (:use [clojure.repl])) 
like image 192
Julien Chastang Avatar answered Sep 21 '22 06:09

Julien Chastang