Frage

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.

War es hilfreich?

Lösung

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.

  • Are they a list? Nope, no parens.
  • Are they a string? Nope, no quotes.
  • Are they a symbol? Nope, there would be a namespace but no name.
  • ...many more cases like this...
  • I give up, this isn't a data structure that represents valid Clojure code.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top