sci

https://github.com/babashka/SCI - also see #babashka and #nbb
borkdude 2020-07-02T13:10:48.136200Z

@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 dependency

borkdude 2020-07-02T13:11:59.136900Z

The 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

Patrick Farwick 2020-07-02T15:05:20.139500Z

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?

borkdude 2020-07-02T15:09:01.140Z

in Clojure 'user is the default namespace, same in sci

borkdude 2020-07-02T15:09:48.140700Z

but that code looks okay

Patrick Farwick 2020-07-02T15:10:34.141700Z

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

lread 2020-07-02T15:18:55.144900Z

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.

borkdude 2020-07-02T15:19:53.145400Z

interesting, thank you. test.check could also be interesting for bb, so keep me posted

lread 2020-07-02T15:21:16.146700Z

sci is really interesting @borkdude, thanks for creating it!

lread 2020-07-02T18:35:19.155800Z

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. defspechttps://github.com/clojure/test.check/blob/6363312afbbe8bb71d6cc9c64c627c98bb7e8b0d/src/main/clojure/clojure/test/check/clojure_test.cljc#L84`defn` whereas deftesthttps://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]

borkdude 2020-07-02T18:37:56.156400Z

The issue seems to be that metadata on defn is not evaluated properly.

borkdude 2020-07-02T18:38:04.156700Z

I've had this issue before, let me take a look

lread 2020-07-02T18:49:24.157300Z

Ya that seems to be it. Don’t you want the above in a git issue on sci?

borkdude 2020-07-02T18:49:33.157500Z

yes please!

lread 2020-07-02T18:49:38.157700Z

will do

lread 2020-07-02T19:07:31.157900Z

done: https://github.com/borkdude/sci/issues/361

borkdude 2020-07-02T19:12:34.158300Z

thanks, will fix ASAP

lread 2020-07-02T19:30:51.159400Z

don’t rush on my account I have plenty of other distractions! 🙂

borkdude 2020-07-02T19:34:51.160100Z

@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

borkdude 2020-07-02T19:35:10.160500Z

that commit is in a branch btw and might disappear once the branch is squashed

lread 2020-07-02T19:36:50.161500Z

Thanks so much! I shall give it a try!

borkdude 2020-07-02T21:31:10.162800Z

@lee Found the root cause and pushed a proper fix, now releasing as 0.1.1-alpha.2

lread 2020-07-02T21:31:33.163100Z

oh cool, thank you!

borkdude 2020-07-02T21:36:39.163300Z

Should be on clojars now

lread 2020-07-02T21:40:35.164100Z

thanks! test.check’s defspec is now failing for me in a different way, I shall dig in and report back.

borkdude 2020-07-02T21:43:04.164300Z

different error is progress

lread 2020-07-02T21:44:08.164500Z

absolutely!

borkdude 2020-07-02T21:50:22.165Z

I'll turn off my computer soon, but I'm looking forward to a fresh error report in the morning

lread 2020-07-02T21:52:00.165800Z

hah! I’ll see what I can figure out before I quit for the day!

lread 2020-07-02T22:19:33.168600Z

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]

lread 2020-07-02T22:20:37.169300Z

I’ll make a git issue for above and likely stop for the day.

lread 2020-07-02T23:13:56.169700Z

https://github.com/borkdude/sci/issues/363