@patrick.farwick I went a little bit into the rabbit hole with specter: https://gist.github.com/borkdude/f6abcb0ff4183df559345503cb9c621c This prints:
#object[com.rpl.specter.impl$reify__714 0x3ba015b1 "com.rpl.specter.impl$reify__714@3ba015b1"]
[{"a" {"b" 10}}]
[{"a" {"b" 10}}]
Not sure why it's not working, but at least it's doing something. It probably requires debugging while using specter as a local/root dependencyThe reason I had to patch the path
macro was that it contained a side effect at macro-expansion time which caused an effect in the Clojure runtime, but not in the sci context
Hey Hey! I actually was going to post an update last night but saved it for this morning. Things finally clicked a bit irt the namespaces piece I have an edit file that just for example looks like this:
(ns edit)
(defn select-a
[m]
(select [:a] m))
and then making the call with
(sci/eval-string "(require '[edit :as e] :reload) (e/select-a {:a 1 :b 2})" {:load-fn load-fn
:namespaces {'edit {'select sr/select*}}})
I think the binding vs namespaces 'user thing took a bit to click in the fact that the 'user was talking about the new user namespace created by sci yeah?in Clojure 'user
is the default namespace, same in sci
but that code looks okay
Yeah, I knew that but idk, like I said, sometimes just takes a bit for things to click in a way I can see them all together
I’m not certain where my testing of rewrite-cljc via sci experimentation will take me, but I happily continue on. I am currently bringing in what I need from test.check and might have found that sci expands the defspec macro into something sci cannot currently handle. I’ll follow up when I’m more sure.
interesting, thank you. test.check could also be interesting for bb, so keep me posted
sci is really interesting @borkdude, thanks for creating it!
Ok, I think I have pinpointed the symptom. Test.check’s defspec
macro is slightly different from clojure.test’s deftest
in the way it attaches metadata.
defspec
https://github.com/clojure/test.check/blob/6363312afbbe8bb71d6cc9c64c627c98bb7e8b0d/src/main/clojure/clojure/test/check/clojure_test.cljc#L84`defn` whereas deftest
https://github.com/borkdude/babashka/blob/640ebce2420133060924522c860c1514b3d6fd60/src/babashka/impl/clojure/test.clj#L631`def`.
Here’s my attempt at distilling the difference to a snippit:
(require '[clojure.pprint :as pprint])
(println "metadata fn on def")
(def ^{:test (fn [] (println "hey there from a"))} a 1)
(pprint/pprint (meta #'a))
((:test (meta #'a)))
(println "\nmetadata fn on defn")
(defn ^{:test (fn [] (println "hey there from af"))} af [])
(pprint/pprint (meta #'af))
((:test (meta #'af)))
Running it through Clojure gives us no error:
metadata fn on def
{:test #object[user$fn__140 0x29f0802c "user$fn__140@29f0802c"],
:line 5,
:column 1,
:file "/Users/lee/proj/oss/play/arglist1.clj",
:name a,
:ns #object[clojure.lang.Namespace 0x29a23c3d "user"]}
hey there from a
metadata fn on defn
{:test #object[user$fn__148 0x1a411233 "user$fn__148@1a411233"],
:arglists ([]),
:line 10,
:column 1,
:file "/Users/lee/proj/oss/play/arglist1.clj",
:name af,
:ns #object[clojure.lang.Namespace 0x29a23c3d "user"]}
hey there from af
Running it through bb (which I use to illustrate sci’s behaviour) shows the difference in :test
metadata:
metadata fn on def
{:line 5,
:column 6,
:end-line 5,
:end-column 53,
:test #object[sci.impl.fns$parse_fn_args_PLUS_body$run_fn__12684
"0x784a4906"
"sci.impl.fns$parse_fn_args_PLUS_body$run_fn__12684@108717768"],
:name a,
:ns #object[sci.impl.vars.SciNamespace "0x84a3722" "user"],
:file "/Users/lee/proj/oss/play/arglist1.clj"}
hey there from a
metadata fn on defn
{:ns #object[sci.impl.vars.SciNamespace "0x84a3722" "user"],
:name af,
:file "/Users/lee/proj/oss/play/arglist1.clj",
:end-column 60,
:column 1,
:line 10,
:end-line 10,
:arglists ([]),
:test (fn [] (println "hey there from af"))}
java.lang.Exception: Cannot call (fn [] (println "hey there from af")) as a function. [at /Users/lee/proj/oss/play/arglist1.clj, line 12, column 1]
The issue seems to be that metadata on defn is not evaluated properly.
I've had this issue before, let me take a look
Ya that seems to be it. Don’t you want the above in a git issue on sci?
yes please!
will do
thanks, will fix ASAP
don’t rush on my account I have plenty of other distractions! 🙂
@lee I have a solution in commit 10e7fa4edbfa8fa0bb32d4b9e179b41938956ba0
so at least you can continue experimenting. I may change the solution, but a test is in place to ensure it won't happen again
that commit is in a branch btw and might disappear once the branch is squashed
Thanks so much! I shall give it a try!
@lee Found the root cause and pushed a proper fix, now releasing as 0.1.1-alpha.2
oh cool, thank you!
Should be on clojars now
thanks! test.check’s defspec is now failing for me in a different way, I shall dig in and report back.
different error is progress
absolutely!
I'll turn off my computer soon, but I'm looking forward to a fresh error report in the morning
hah! I’ll see what I can figure out before I quit for the day!
Oh I think I see what is happening. deftest
’s meta :test
function https://github.com/clojure/test.check/blob/6363312afbbe8bb71d6cc9c64c627c98bb7e8b0d/src/main/clojure/clojure/test/check/clojure_test.cljc#L88 which likely has not been evaluated by sci yet.
I think it distills down to something like so:
(defn ^{:test (clojure.core/fn []
(println "hey there from af meta fn")
(af))}
af []
(println "hi from af"))
When evaluated, results in:
Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:54).
Could not resolve symbol: af [at line 3, column 18]
I’ll make a git issue for above and likely stop for the day.