clojure-emacs/sayid

Error when trying to start inner-trace

DonyorM opened this issue · 8 comments

When I try to perform an inner-trace on a function (sayid-inner-trace-fn) I get the following error on the REPL

https://gist.github.com/DonyorM/dbe0f39bcaec5f156fbb607fc297093b

When trying to run the function I get the following errors on the repl before the function result is outputted:

(AFn.java:18)
    java.util.concurrent.FutureTask.run (FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java.lang.Thread.run (Thread.java:745)

The trace is not registered in the workplace.

I am testing this with the newest spacemacs, using cider 0.15.0snapshot and sayid 0.0.11

bpiel commented

@DonyorM There's probably something in the source that sayid can't handle. Would you be willing to paste the source of the function here?

Here's the function, I'll try seeing if I can figure out the issue.

(def do-triangle
  (fn [t]
    (let [tri (vec t)]
      (letfn [(countroute [row key]
                (min-key #(+ (get-in tri [(inc row) %]) %) key (inc key)))]
        (loop [cnt (get-in tri [0 0])
               previous 0
               row 1]
          (println previous)
          (if (= row (dec (count tri)))
            (+ cnt (min (get-in tri [row previous]) (get-in tri [row (inc previous)])))
            ;;else
            (let [next (min-key (partial countroute row) previous (inc previous))]
              (recur (+ cnt next) next (inc row)))))))))
bpiel commented

It's almost definitely the (fn [t].... I always test with defn.

Ok, new error, seems to be with the let form. Does sayid not support let statements?

Error gist: https://gist.github.com/DonyorM/70b6114951796bf3c0fac462fb181968

And here's the function:

(defn do-triangle [t]
    (let [tri (vec t)]
      (letfn [(countroute [row key]
                (min-key #(+ (get-in tri [(inc row) %]) %) key (inc key)))]
        (loop [cnt (get-in tri [0 0])
               previous 0
               row 1]
          (println previous)
          (if (= row (dec (count tri)))
            (+ cnt (min (get-in tri [row previous]) (get-in tri [row (inc previous)])))
            ;;else
            (let [next (min-key (partial countroute row) previous (inc previous))] ;;this is line 365, the source of the error
              (recur (+ cnt next) next (inc row))))))))
bpiel commented

Whoa, I didn't know about letfn! Sayid does support inner-trace on let.

I believe the problem is that it isn't handling having multiple (two, in this case) forms in the body of loop. My guess is that removing the println would fix this one. This is a bug, but shouldn't be too hard to fix. I'll make an issue.

Here's where things go wrong:
https://gist.github.com/DonyorM/70b6114951796bf3c0fac462fb181968#file-gistfile1-txt-L687-L692

Yeah, it's a nice function, I discovered it while looking at other's solutions for 4clojure challenges.

However, sayid doesn't like it. Function stilled failed until I replaced it with an ordinary let. After removing the println and the letfn, it worked fine. Thanks for working through that with me.

Stacktrace, if that helps: https://gist.github.com/DonyorM/84e6dcdd9d838cd96d4579eb0f2e8a61

bpiel commented

Thank you for your patience with sayid. Stacktrace does help. I'll make another issue.