Resolve 函数在 ClojureScript 中引发错误,但不会在 Clojure 中引发错误 [英] Resolve function throws an error in ClojureScript but not Clojure
问题描述
以下程序在 Clojure 中按我的预期工作,但在 ClojureScript 中引发错误.我想知道这是一个错误还是该功能在 ClojureScript 中根本不可用,或者我是否需要重新考虑我尝试这样做的方式.非常感谢您提前提供帮助.
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
推荐答案
resolve
在 ClojureScript 中不存在.事实上,ClojureScript 没有 Vars.
resolve
doesn't exist in ClojureScript. In fact, ClojureScript does not have Vars.
可以通过各种技巧(例如将 aget
与命名空间对象一起使用)来调用其名称是动态构造的函数,但是除非导出所有相关符号,否则这些技巧肯定会因高级编译而中断.此外,即使有更宽松的编译设置,目前也没有人获得官方支持.
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.
这篇关于Resolve 函数在 ClojureScript 中引发错误,但不会在 Clojure 中引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!