I think there is an inconsistency handling metadata. The first eval-form
returns {:default true}
while the second returns nil. Interestingly, if I replace v
with a constant value, it works as expected
@markaddleman The most common use case is that the form you are evaluating comes from the parser:
user=> (def ctx (sci/init {:namespaces {'user {'v 1}}}))
#'user/ctx
user=> (meta (sci/eval-form ctx '^:foo {:x v}))
nil
user=> (def reader (sci/reader "^:foo {:x v}"))
#'user/reader
user=> (def v (sci/parse-next ctx reader))
#'user/v
user=> (meta v)
{:foo true}
What is your use case of doing it like the above?I have a data file that is an edn map that looks something like
{:a [s1], :b [s1 s2]}
I only want to eval either the value of :a
or :b
. When I eval :a
, s2
is not available in the environment
So, my current approach is to slurp in the datafile, parse it as edn, and eval the value of :a
with sci
@markaddleman I was able to reproduce your case like this:
user=> (meta (sci/eval-string "^:foo {:x (+ 1 2 3)}"))
nil
user=> (meta (load-string "^:foo {:x (+ 1 2 3)}"))
{:foo true}
@markaddleman Fixed on master
Great. Thanks!
Are you using deps.edn?
Yep. I'll check out master in about an hour