I'm currently learning Clojure, and I'm evaluating sample code from the book
in begin_src
/end_src
blocks. Works quite well, as org adds structure to
otherwise unrelated pieces of code.
The problem starts when these pieces become related, i.e. sample code
for chapter on agents uses a function defined for refs two chapters back.
So on attempt of evaluating the last block from a new nrepl session,
an undefined function
error is thrown. Then I have to find the block
where the relevant function is actually defined and evaluate that.
And I'm lucky if it doesn't depend on anything else.
One solution could be to re-evaluate sequentially all the source blocks. That would certainly work, but a very large number of blocks would be evaluated needlessly, as they're not among the dependencies of the block that I actually want to evaluate.
I'm thinking that perhaps some mechanism akin to auto loading could be implemented, e.g.:
#+begin_src clojure :defines square
(defn square [x]
(* x x))
#+end_src
So that when I'm evaluating this block:
#+begin_src clojure
(square 5)
#+end_src
and "Unable to resolve symbol: square" appears, org will try to find if any of the source blocks in current buffer define this function.
I'm open to any other suggestions to solve this problem, as long as the solution allows me to effectively store the code samples from the whole book in a single org file.