Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to show stepwise how Clojure evaluates a function?

I'm just starting to teach myself Clojure. As part of supplementing my studies I've watched a few UC Berkley lectures by Brian Harvey on the topic of functional programming. In his second lecture on functional programming, at about minute 34, he uses the applic function to show the order of evaluation. Does Clojure have a feature similar to this? It sure would be handy to see the order of evaluation as I work to understand the whys and wherefores.

like image 855
driftlessjeff Avatar asked Aug 04 '11 01:08

driftlessjeff


1 Answers

You can do just in REPL (answer by Mike Meyer in Clojure mailing list: Debugging in Clojure)

=> (use 'clojure.contrib.trace)
nil
=> (defn foo [coll] (reduce + coll))
#'web-db.core/foo
=> (defn bar [coll] (map inc coll))
#'web-db.core/bar
=> (dotrace [foo bar] (foo (bar [1 1 1])))
TRACE t3868: (bar [1 1 1])
TRACE t3868: => (2 2 2)
TRACE t3869: (foo (2 2 2))
TRACE t3869: => 6
6

there are also Clojure Debugging Toolkit ("Ridiculously long instructions on how to use it are here: http://georgejahad.com/clojure/emacs-cdt.html ")

And some IDE (like Eclipse with Counterclockwise plugin) allow to debug: to set breakpoints, see locals, step in/out, ...

like image 98
zmila Avatar answered Jan 01 '23 21:01

zmila