Reputation: 1479
I'm currently implementing a different language (Shen) in Clojure.
Shen has a symbol "./" but in Clojure this is interpreted before evaluation and thus results in an error. I do not need "./" inside the macro which is compiling this function to Clojure code.
Is there a way to ignore this? I think it is interpreted as an qualified symbol but without a name, since replacing it by a/ or xyz/ results in the same error messages.
My current macro is as simple as
(defmacro kl/trap-error [x [y z r]] `(try ~x (catch Exception '~z ~r)))
But when I call it with Shen code the following happens:
kl=> (trap-error (/ 1 0) (./ E (error-to-string E)
RuntimeException Invalid token: ./ clojure.lang.Util.runtimeException (Util.java:156)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: E in this context, compiling:(NO_SOURCE_PATH:0)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: E in this context, compiling:(NO_SOURCE_PATH:89)
I hope someone can help me with this.
Thanks in advance.
Upvotes: 2
Views: 394
Reputation: 91917
This is not possible without modifying the Clojure reader (a privilege which is not given to Clojure programmers). Your statement "Shen has a symbol ./
but in Clojure this is interpreted before evaluation and thus results in an error" is incorrect, though - no interpretation or evaluation goes on at all, because the reader sees these characters and can't even figure out what data type they should be.
Upvotes: 2