sci

https://github.com/babashka/SCI - also see #babashka and #nbb
mauricio.szabo 2020-08-24T01:24:09.016600Z

Hi, @borkdude. Just a single question: I'm using SCI on ClojureScript, and want to pass ClojureScript records to, and from SCI. So, I saw the :readers option. But if I send an options like {'example.Error ex/map->Error}, when I evaluate the code #example.Error{:type "SomeError, :message "A Message"} it returns a PersistentArrayMap, not the record

borkdude 2020-08-24T06:12:50.017300Z

@mauricio.szabo Do you want to read records from source code strings?

borkdude 2020-08-24T06:21:40.017700Z

I can reproduce the problem:

cljs.user=> (type (sci/eval-string "#example.Error{:type \"SomeError\", :message \"A Message\"}" {:readers {'example.Error map->Error}}))
cljs.core/PersistentArrayMap

borkdude 2020-08-24T06:21:47.017900Z

Made an issue here: https://github.com/borkdude/sci/issues/386

borkdude 2020-08-24T12:34:17.018500Z

@mauricio.szabo Do you need a new mvn/version or do you use it as a git dep?

mauricio.szabo 2020-08-24T12:57:35.019100Z

A mvn/version is better, because I'm using on Shadow-CLJS 😄. Thanks a lot!

mauricio.szabo 2020-08-24T13:15:33.019500Z

(BTW, that was FAST! 😄)

borkdude 2020-08-24T13:28:33.019800Z

@mauricio.szabo ok: borkdude/sci {:mvn/version "0.1.1-alpha.7"}

borkdude 2020-08-24T13:34:46.020400Z

Btw, since yesterday night the CLJS tests for sci run really sloooow on my machine, no idea why

borkdude 2020-08-24T13:35:07.020800Z

on CI I don't really observe this difference

borkdude 2020-08-24T13:39:35.021700Z

I'm also observing this with 0.1.0 which was released quite a while ago. I guess my holiday laptop (Macbook Air) just doesn't cut it anymore, but the JVM tests are still super fast.

mauricio.szabo 2020-08-24T14:53:27.022300Z

@borkdude well, everything seems normal here on my machine with SCI tests... maybe some node/macOS update?

kwrooijen 2020-08-24T20:45:34.023700Z

Hey, I'm trying to use clojure.walk/macroexpand-all inside of sci but it's failing with the classic Caused by: <http://java.io|java.io>.FileNotFoundException: Could not locate clojure/spec/alpha__init.class, clojure/spec/alpha.clj or clojure/spec/alpha.cljc on classpath. Basically I'm running this:

(sci.core/eval-string
   "(macroexpand-all '(-&gt; 1 println))"
   {:bindings {'macroexpand-all clojure.walk/macroexpand-all}})
;;=&gt; (println 1)

borkdude 2020-08-24T20:46:20.024500Z

Don't do that :)

kwrooijen 2020-08-24T20:46:31.024700Z

😢

kwrooijen 2020-08-24T20:46:33.024900Z

Why not?

borkdude 2020-08-24T20:47:23.025700Z

Sci already has macroexpand. The macroexpand-all should call that macroexpand, not clojure's own macroexpand.

kwrooijen 2020-08-24T20:48:04.026Z

So I need to re-implement macroexpand-all in sci?

borkdude 2020-08-24T20:48:14.026200Z

Yes, or contribute it to sci

kwrooijen 2020-08-24T20:49:05.026900Z

All right, for the short-term would evaluating the implementation inside of sci be enough?

borkdude 2020-08-24T20:49:11.027200Z

I think so yes

kwrooijen 2020-08-24T20:49:12.027300Z

I'd love to contribute though 🙂

borkdude 2020-08-24T20:49:56.028200Z

You can contribute by making an issue first :)

kwrooijen 2020-08-24T20:50:57.029Z

All right, well I actually already tried that. But I didn't get the result I expected:

(sci.core/eval-string "
(defn walk [inner outer form]
  (cond
   (list? form) (outer (apply list (map inner form)))
   (map-entry? form)
   (outer [(inner (key form)) (inner (val form))])
   (seq? form) (outer (doall (map inner form)))
   (record? form)
     (outer (reduce (fn [r x] (conj r (inner x))) form form))
   (coll? form) (outer (into (empty form) (map inner form)))
   :else (outer form)))

(defn prewalk [f form]
  (walk (partial prewalk f) identity (f form)))

(defn macroexpand-all [form]
  (prewalk (fn [x] (if (seq? x) (macroexpand x) x)) form))

 (macroexpand-all '(-&gt; 1 println))")
;;=&gt; (-&gt; 1 println) ;; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; INCORRECT
When I evaluate these functions, and run it locally, it does work

borkdude 2020-08-24T20:53:35.029300Z

ok, let me try

borkdude 2020-08-24T20:54:09.029600Z

oh I see. yes, well, that has a different reason

borkdude 2020-08-24T20:54:37.030200Z

The -&gt; is built in kind of as a primitive in sci, it was one of the first macros I implemented, when user-defined macros weren't possible yet

borkdude 2020-08-24T20:54:46.030500Z

so it's not really expanded like other macros

kwrooijen 2020-08-24T20:55:26.031Z

Oh! I see. -&gt;&gt; does work

kwrooijen 2020-08-24T20:55:29.031300Z

very interesting

borkdude 2020-08-24T20:57:55.031800Z

I have trouble finding where exactly the implementation of that "special" macro is

borkdude 2020-08-24T20:58:45.032100Z

ah, there it is, in analyzer.cljc:

;; TODO: implement as normal macro in namespaces.cljc
                -&gt; (expand-&gt; ctx (rest expr))
                ;; TODO: implement as normal macro in namespaces.cljc
                as-&gt; (expand-as-&gt; ctx expr)
                

kwrooijen 2020-08-24T21:01:32.032600Z

https://github.com/borkdude/sci/blob/f6389378181b24b828566ac5307eca25aadf119e/src/sci/impl/analyzer.cljc#L27 Does this mean it's also applicable for as-&gt; ?

borkdude 2020-08-24T21:01:40.032900Z

yes

borkdude 2020-08-24T21:02:11.033300Z

it's historical, not necessarily the way it has to be now

kwrooijen 2020-08-24T21:04:05.033600Z

Maybe I can cook something up then

borkdude 2020-08-24T21:06:54.033800Z

Sure

borkdude 2020-08-24T21:20:52.034200Z

I think we already have tests for -&gt; so if they keep working, you don't have to add new ones I think

kwrooijen 2020-08-24T21:22:08.034800Z

Ah ok, I'll remove those (and update my branch)

borkdude 2020-08-24T21:22:23.035200Z

or you can separate them out from the bug chunk of core tests and move them to their own deftest, which is cleaner I think

kwrooijen 2020-08-24T21:23:55.035600Z

I see, I'll move them then

borkdude 2020-08-24T21:26:23.035900Z

You can also add a test for macroexpanding it

kwrooijen 2020-08-24T21:31:42.036300Z

Done, simple tests but they show what's expected

borkdude 2020-08-24T21:37:41.037100Z

I just merged a huge PR (having to do with the new stack trace support in babashka), so there's a conflict now. Can you solve it? Can wait till tomorrow, since I'm calling it a day

borkdude 2020-08-24T21:38:34.037500Z

Btw, one more thing: the namespaces-test namespace is intended for tests related to ns etc

borkdude 2020-08-24T21:38:51.037900Z

So you can still stick your -&gt; tests in core_tests.cljc but in a separate deftest

kwrooijen 2020-08-24T21:39:05.038100Z

Ah right

kwrooijen 2020-08-24T21:39:16.038400Z

All right, I'll fix that tomorrow 🙂

kwrooijen 2020-08-24T21:39:38.038600Z

Or well might as well do it now lol

kwrooijen 2020-08-24T21:40:12.039Z

Anyway, good night! Calling it a day as well 👋