sci

https://github.com/babashka/SCI - also see #babashka and #nbb
lread 2020-07-10T21:02:26.243500Z

Heya @borkdude! I’m assuming https://github.com/borkdude/sci/blob/88bb9c542fd1d404fd3bb25eb556e86668ef30de/src/sci/impl/interpreter.cljc#L587? Reason I ask is because I am stripping sci positional metadata when calling rewrite-cljc API but this adds an unwanted :line metadata back in for me.

lread 2020-07-10T21:04:37.245500Z

In my unit tests it comes out as :line nil which would be easy to address in sci, but then when I tried to distill the issue I see :line 1 which currently has me confused.

lread 2020-07-10T21:09:21.245900Z

Here’s my little distillation attempt:

(require '[clojure.walk :as walk])
(require '[sci.core :as sci])

;; my utility fns to remove sci positional metadata
(defn remove-sci-meta [expr]
  (walk/prewalk (fn [e]
                  (if-let [orig (meta e)]
                    (let [new (dissoc orig :line :column :end-line :end-column)
                          new (if (seq new) new nil)]
                      (with-meta e new))
                    e))
                expr))

(defn fn-without-sci-meta-on-args
  "Wrap `target-fn` removing all sci positional metadata from call arguments."
  [ target-fn ]
  (fn [ & fn-args ]
    (apply target-fn (map #(remove-sci-meta %) fn-args))))

;; a dummy api fn
(defn my-api-fn [a] a)

;; calling this under Clojure
(meta (my-api-fn ^:hi [1 2 3]))
;; => {:hi true}

;; calling same fn bound to sci
(sci/eval-string "(meta (my-api-fn ^:hi [1 2 3]))" {:bindings {'my-api-fn my-api-fn}})
;; => {:line 1, :column 19, :end-line 1, :end-column 31, :hi true}

;; calling same fn bound to sci with metadata stripped from args
(sci/eval-string "(meta (my-api-fn ^:hi [1 2 3]))" {:bindings {'my-api-fn (fn-without-sci-meta-on-args my-api-fn)}})
;; => {:hi true, :line 1}

borkdude 2020-07-10T21:27:16.246700Z

It's a little bit too late for me to dive into this now, but hopefully I'll have time next week. Tomorrow I have to prepare a presentation about babashka+sci for Clojure NYC 🙂

borkdude 2020-07-10T21:28:45.247300Z

If you can meanwhile distill this in an issue, and describe the exact problem you are encountering, that would probably be good

lread 2020-07-10T21:52:23.248400Z

Thanks @borkdude! I shall continue to tinker. Have a great presentation! Looking forward to the video!

borkdude 2020-07-10T21:53:27.249200Z

Maybe it would be interesting to see what happens if you leave out the "fixing" of the metadata, see what tests will fail

lread 2020-07-10T21:55:29.250800Z

I have a fix for the fix that fixes my tests (a tongue twister!), but I don’t fully understand the results of my distill attempt yet. I’ll take some time to figure it out.

borkdude 2020-07-10T21:55:54.251100Z

Also run the babashka tests if you tinker with the sci code itself

lread 2020-07-10T21:56:11.251300Z

Ah good tip, thanks.