2024年Clojure状态调查!分享你的想法。

欢迎!有关如何使用本服务的更多信息,请参阅关于页面。

+1
ClojureScript

当我想要将一组固定的字符串编码到代码中时,使用 #{...} 产生的代码比使用(set #js [...]) 产生的代码大两倍,后者在开头生成集合。通过检查没有优化的代码输出,我得到了以下针对 #{...} 的代码:

`my_set = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1504, ["studio",null,"etisalat",null,"mortgage",null,"xn--gecrj9c",null,"technology",null,"nl",null,"lilly",null,"wolterskluwer",null,"schmidt",null,"hisamitsu",null,"total",null,"blue",null,"aw",null,"zw",null,"properties",null,"amex",null,"linde",null,"arpa",null,"ieee",null, ... [a lot more] ...,"fairwinds",null,"lk",null,"itau",null], null), null);`

以及针对 (set #js [...]) 的以下代码

`my_set = cljs.core.set(["aaa","aarp","abarth","abb","abbott","abbvie", ... [a lot more] ...,"yoga","yokohama","you","youtube","yt","yun","za","zappos","zara","zero","zip","zm","zone","zuerich","zw"]);`

(在高级编译中被进一步优化)。对于所有1500个TLD的列表,前者在高级模式下产生20KB的生成的代码,而后者只需要10KB。为什么构建了内嵌的PersistentArrayMap?为什么不可以用JS数组传递给它呢?

登录注册来回答这个问题。

...