This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-02
Channels
- # arachne (8)
- # beginners (48)
- # carry (4)
- # chestnut (2)
- # cider (12)
- # cljs-dev (3)
- # clojure (28)
- # clojure-belgium (2)
- # clojure-brasil (1)
- # clojure-greece (4)
- # clojure-russia (6)
- # clojure-spec (1)
- # clojurescript (32)
- # cursive (11)
- # defnpodcast (2)
- # euroclojure (1)
- # hoplon (43)
- # jobs (2)
- # jobs-rus (10)
- # off-topic (11)
- # om (32)
- # onyx (28)
- # overtone (5)
- # parinfer (4)
- # planck (11)
- # protorepl (2)
- # reagent (2)
- # spacemacs (3)
- # yada (5)
I'm reading through The Joy of Clojure, and it took a long while to digest its implementation of QuickSort. I'd like to know what non-editor tools I can use to see how clojure expressions evaluate. Any recommendations?
I figure that there should be a way to write a macro that prints the source of each sub-expression as it evaluates, along with the results at each step (map of bound variable names to values), and indexes on the order of evaluation. I just.... don't want to write it (and also, there might be complications with that and lazy functions?)
The absolute fastest way to comprehend code in clojure @montanonic is to use the REPL.
which is what I'm doing
but, I'd like to see a trace of each step in the evaluation of a function
with the currently bound local variables and their values
if that makes sense
so I can see how it evaluates
okay, just was wondering if there was an obvious macro for doing that in core clojure
and in this case, no reduce
though reductions
is good to know
(defn sort-parts [work]
(lazy-seq
(loop [[part & parts] work]
(if-let [[pivot & xs] (seq part)]
(let [smaller? #(< % pivot)]
(recur (list*
(filter smaller? xs)
pivot
(remove smaller? xs)
parts)))
(when-let [[x & parts] parts]
(cons x (sort-parts parts)))))))
(defn qsort [xs]
(sort-parts (list xs)))
I've more-or-less figured out exactly how it's working. Just, for future reference, it'd be nice to give a function like that some random input, and see literally every step of it evaluate.
Haha, totally fair point. And coming from Haskell, I totally can see how most clojure stuff wouldn't be hard to grok
loop/recur
means that: We are doing a recursive thing but b/c of the JVM we can’t use tail call recursion.
yeah, I grok that part
I think I have the whole quicksort implementation down
Just, I'd like to see it working step by step 🙂
I’ve met Fogus in person and he is a smart and fun person. That code is a great example, but I don’t see it often.
Yeah, it's more a matter of, I want a macro that I can use whenever I see something that confuses me, run it through the macro with some sample input, see how it evaluates
I'm going to pilfer http://stackoverflow.com/questions/2352020/debugging-in-clojure#2352491 and see if any of the recommendations suit what I'm looking for
deftrace from http://clojure.github.io/tools.trace/ works beautifully