Search code examples
vimclojureclojurescriptread-eval-print-loop

How to evaluate reader conditionals from a Clojure REPL


I understand how to write code using reader conditionals. But I'm not able to evaluate code with reader conditionals in the REPL, which makes it rather difficult to use Vim Fireplace to evaluate code in my .cljc files. (I imagine Emacs and Cursive users would have similar problems, but perhaps their different approaches give them ways around this.)

The error I get when I try to evaluate a .cljc with reader conditionals using Fireplace is

RuntimeException Conditional read not allowed  clojure.lang.Util.runtimeException (Util.java:221)

I was able to find this article which points out that if you try to use reader conditionals from a file with a .clj extension, you'll get this error. That suggests to me that the lein REPL is attempting to evaluate the code as though it's coming from a .clj file.

Is there a way to get the lein repl to interpret things differently to avoid this problem? Some other way around this? Or is this just not possible?


Solution

  • I updated tools.repl from version 0.2.3 to 0.2.11, and that seems to have done the trick! Not sure what the minimal version is that would solve this, but I can't imagine there's much point in not just upgrading to the latest.

    (I should also note that I upgraded lein from 2.5.1 to 2.6.1, but that didn't solve the issue in isoloation; Doubt it's necessary, but worth trying if the above doesn't resolve things for you...)