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.
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.
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}
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 🙂
If you can meanwhile distill this in an issue, and describe the exact problem you are encountering, that would probably be good
Thanks @borkdude! I shall continue to tinker. Have a great presentation! Looking forward to the video!
Maybe it would be interesting to see what happens if you leave out the "fixing" of the metadata, see what tests will fail
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.
Also run the babashka tests if you tinker with the sci code itself
Ah good tip, thanks.