This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-02
Channels
- # beginners (130)
- # calva (3)
- # cider (13)
- # circleci (1)
- # cljsrn (19)
- # clojure (106)
- # clojure-europe (10)
- # clojure-losangeles (1)
- # clojure-nl (9)
- # clojure-uk (33)
- # clojurescript (16)
- # code-reviews (24)
- # conjure (11)
- # cursive (41)
- # data-science (9)
- # datomic (63)
- # fulcro (19)
- # graphql (12)
- # helix (4)
- # kaocha (2)
- # leiningen (3)
- # malli (8)
- # meander (1)
- # off-topic (17)
- # re-frame (16)
- # reitit (12)
- # sci (32)
- # shadow-cljs (73)
- # spacemacs (31)
- # sql (38)
- # tools-deps (26)
- # xtdb (28)
@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?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
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]
@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
thanks! test.check’s defspec is now failing for me in a different way, I shall dig in and report back.
I'll turn off my computer soon, but I'm looking forward to a fresh error report in the morning
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]