This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-06
Channels
- # announcements (3)
- # aws (3)
- # babashka (9)
- # beginners (87)
- # calva (3)
- # chlorine-clover (7)
- # cider (6)
- # clj-kondo (1)
- # cljs-dev (31)
- # cljsrn (7)
- # clojure (26)
- # clojure-berlin (5)
- # clojure-europe (84)
- # clojure-nl (3)
- # clojure-uk (13)
- # clojurescript (39)
- # core-async (4)
- # core-logic (3)
- # cursive (3)
- # datomic (10)
- # devcards (5)
- # duct (2)
- # emacs (3)
- # events (1)
- # fulcro (6)
- # jobs (4)
- # kaocha (12)
- # london-clojurians (1)
- # off-topic (21)
- # other-languages (2)
- # pathom (5)
- # pedestal (1)
- # re-frame (1)
- # reitit (3)
- # remote-jobs (6)
- # reveal (6)
- # sci (34)
- # shadow-cljs (99)
- # tools-deps (99)
I bumped into this:
(sci/eval-string "(require '[clojure.set :as set]) (set/union {}{})" opts)
=> {}
but
(sci/eval-form (sci/init {}) (edn/read-string "(require '[clojure.set :as set]) (set/union {}{})"))
Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:52).
Could not resolve symbol: clojure.set
how can I interpret a form previously read by edn/read-string
? Or do I have to use the sci version?@katox ah I see. the EDN you read is not well-formed as clojure code due to EDN supporting quotes as single things, they are not related to what follows. It's just an ordinary symbol.
user=> (edn/read-string "'[1 2 3]")
'
compare:
user=> (def form (read-string "(do (require '[clojure.set :as set]) (set/union #{1 2} #{2 3}))"))
#'user/form
user=> (sci/eval-form (sci/init {}) form)
#{1 3 2}
hmm, if I replace the quote symbol with the actual quote
function it still doesn't do the thing
user=> (def form (edn/read-string "(do (require (quote [clojure.set :as set])) (set/union {}{}))"))
#'user/form
user=> form
(do (require (quote [clojure.set :as set])) (set/union {} {}))
user=> (sci/eval-form (sci/init {}) form)
{}
@katox I think you can also use edamame for this: it allows parsing EDN++, where ++ is just the amount you need
another thing - is there a convenience function to import the whole ns into sci :namespaces
?
I use this
(defn map-sym [ns syms]
(into {} (map (fn [sym] [sym @(resolve (symbol (name ns) (name sym)))]) syms)))
but kinda too simplistic 🙂that works too. note that if you're compiling down to a native-image, having resolve in a function body isn't great for size
@katox What I mean is: if you use map-sym
only on top-level values, that's ok, but if you use this at run-time in the graalvm binary, it will add 10-20 MB to the binary for nothing
Oops, sorry, I mean https://github.com/borkdude/dynaload
yes. so:
(def my-namespace (map-sym ...))
is good, but:
(defn foo [x] (get (map-sym ...) x))
is not that great for binary size.A relatively simple graalvm binary with java 11 and clojure 1.10.2-alpha3 yields about 11mb. When you accidentally use resolve at runtime it will become 25mb.