Resolve function throws an error in ClojureScript but not Clojure

蹲街弑〆低调 提交于 2019-12-09 02:47:01

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/12020576/resolve-function-throws-an-error-in-clojurescript-but-not-clojure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!