Today my small discovery was

I started doing the 4clojure problems on the new host, and wondering if I could do them in my editor, found GitHub - PEZ/rich4clojure: Practice Clojure using Interactive Programming in your editor by @PEZ. It’s really nice.

On a related note I discovered CIDER’s profiling, so I can compare running time of solutions (taken from the gist linked with each problem in rich4clojure, or by going to the 4clojure.oxal.org site which has more solutions usually).

Feel free to add your own small discoveries, I’m putting this in the beginner category but it’s not necessarily just for beginners, more “beginner’s mind” :slight_smile:

4 Likes

I found a link to REPL Debugging: No Stacktrace Required in a workflow thread here that gave this tip, obvious in retrospect but it never crossed my mind:

To blindly subdivide the problem, start with the your problem case and explicitly eval all the subpieces. This will often identify which subpiece is the problem, and you can work your way down until you have a problem that you can understand at a glance. Since foo uses only one name, n, I will temporarily def that name at the top level:

(def n 24)

Now I can evaluate every subform in foo, just by putting my cursor at the end of each form and sending that form to my REPL

This seems like a nice generic and quick version of CIDER’s debugger.

I recommend that blog post btw, I thought it was really well written.

I have hot keys set up in VS Code for:

  • def’ing the current/selected symbol with a value read from a prompt
  • defing a symbol/expression pair from a let binding

So when I have code like this inside a function:

  (let [a (* b 32)
        c (+ a b)]
    (some-thing a c))

I can put my cursor on b, press ctrl+alt+space i and an input box opens in VS Code (Calva) so I can type any value and hit return. Then I can highlight a (* b 32) and press ctrl+alt+space d to create a def of that, then highlight c (+ a b) and press ctrl+alt+space d again, and then with the cursor on (some-thing a c) I can press ctrl+enter to evaluate that with a and c available.

seancorfield/vscode-calva-setup: My VS Code / Calva / Portal / Joyride setup (github.com)

5 Likes