nbb 2025-11-23

Has anybody used source-fn in nbb? I'm getting

user=> (clojure.repl/source-fn multittt.stream/transfer)
Doesn't support namespace: function(n,r,p){var y=0===f?null:Dn.g(f);$APP.l(d)&&(d.h?d.h(b,y):d.call(null,b,y));y[0]=n;y[1]=r;for(y[2]=p;;)if(n=Q(e,a,y),!$(rv,n))return n}
Am I using/invoking it wrong or is this not (yet) available in nbb?

source-fn is probably implemented in SCI or so. if you compile nbb with pseudo-names true you get more readable output

perhaps it expects a symbol rather than a function

yep, that's just it.

user=> (clojure.repl/source-fn "dude")
Execution error (ClassCastException) at user/eval4 (REPL:1).
class java.lang.String cannot be cast to class clojure.lang.Symbol (java.lang.String is in module java.base of loader 'bootstrap'; clojure.lang.Symbol is in unnamed module of loader 'app')

like

user=> (clojure.repl/source-fn (symbol "multittt.stream" "transfer"))

or just 'multittt.stream/transfer

user=> (clojure.repl/source-fn 'multittt.stream/transfer)
nil

yeah it doesn't work in nbb because nbb implements loading in a custom way from the normal SCI workflow. normally it expects you to use load-fn https://github.com/babashka/sci/blob/ba20a7b4eb2bca92a905730f3a9470e3442bfb17/src/sci/impl/namespaces.cljc#L1859 but that's not used in nbb

it's something that could be fixed in nbb. don't have much time the coming weeks but feel free to make an issue

👍 1

any other ideas on how i might avoid having to escape scittle scripts? this is my current pain

(def renderelem [:script {:type "application/x-scittle"} " 
      (require
      '[replicant.string :as s]
      '[clojure.edn :as edn]
      '[replicant.dom :as r])
      (defn render-element [elem hic]
      (println elem)
      (def el (js/document.getElementById elem))
      (println hic)
      (r/render el (edn/read-string hic))
      \"\"
       )      
      (set! (.-renderelement js/window) render-element)

      "])

that's a different kind of question. please start a new thread so we can keep things separate

I'll have another think about it

@gregorybleiker Re: "avoid having to escape scittle scripts" here's how I did that in https://github.com/chr15m/cljs-josh/. Define your Scittle quoted. https://github.com/chr15m/cljs-josh/blob/main/josh.cljs#L353-L355

(def loader
  '(defonce _josh-reloader
     (do
Use pr-str to inject it into a script tag: https://github.com/chr15m/cljs-josh/blob/main/josh.cljs#L434-L435
loader-script (str "<script type='application/x-scittle'>"
                               (pr-str loader) "</script>")
Hope that helps!

In your case you're using Reagent to render it, so you can do this:

(def renderelem [:script {:type "application/x-scittle"} (pr-str my-script)])

You may need to use dangerouslySetInnerHTML to set the actual contents, not sure:

[:script
 {:dangerouslySetInnerHTML
  {:__html (pr-str my-script)}}]

@chris358 so cool! Thanks a lot! Should we maybe post this approach in #scittle?