11

The following program works as I expected in Clojure, but throws an error in ClojureScript. I'm wondering if this is a bug or the feature simply isn't available in ClojureScript or if I need to rethink the way I'm attempting to do this instead. Thanks a lot for the help in advance.

; Clojure...
(defn foo [x] x)
(defn foobee [x] (str (foo x) "bee"))

(println
  ((resolve (symbol (str "foo" "bee"))) "bizzee"))

;=> bizzeebee

; ClojureScript...
(defn foo [x] x)
(defn foobee [x] (str (foo x) "bee"))

(.log js/console
  ((resolve (symbol (str "foo" "bee"))) "bizzee"))

;=> Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
bryanwoods
  • 195
  • 8
  • I've posted the answer to the main issue below, but I'm wondering where did that exception come up? It's a Java exception, not a JS error, so I'm guessing it was a problem during compilation or in a browser repl session. The compiler should definitely have no trouble compiling this code and indeed it doesn't on my box, so if it did happen at compile time, perhaps it could be an issue with some part of ClojureScript code you haven't pasted here? If it's a browser repl thing, could you paste a log of a browser repl session producing this exception in the server somewhere? – Michał Marczyk Aug 18 '12 at 17:47
  • If it doesn't turn out to be something obvious, a minimal breaking example and the release number / commit sha of your ClojureScript version would be very useful. – Michał Marczyk Aug 18 '12 at 17:50
  • Thanks for your help. I was trying to compile with both simple and advanced optimizations but hadn't tried compiling with no optimizations. Doing so deferred this to a JavaScript-level error. – bryanwoods Aug 18 '12 at 20:24

1 Answers1

15

resolve doesn't exist in ClojureScript. In fact, ClojureScript does not have Vars.

Calling a function whose name is constructed dynamically is possible through various hacks (like using aget with the namespace object), which are however guaranteed to break with advanced compilation unless all the relevant symbols are exported. Also, currently none enjoy official support even with the more permissive compilation settings.

Michał Marczyk
  • 83,634
  • 13
  • 201
  • 212
  • 1
    @bryanwoods For an example of a hack by yours truly see: http://stackoverflow.com/a/30892955/1852043 (note that it does require the symbol to be exported). – Marcin Bilski Jun 17 '15 at 13:32
  • No longer true, it seems. https://cljs.github.io/api/cljs.core/resolve – Jeff Evans Sep 28 '20 at 21:15