nbb

Gregory Bleiker 2025-11-23T13:23:02.178299Z

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?

borkdude 2025-11-23T13:25:00.313099Z

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

borkdude 2025-11-23T13:27:07.559169Z

perhaps it expects a symbol rather than a function

borkdude 2025-11-23T13:27:31.485569Z

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')

Gregory Bleiker 2025-11-23T13:33:36.126439Z

like

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

borkdude 2025-11-23T13:33:54.675689Z

or just 'multittt.stream/transfer

Gregory Bleiker 2025-11-23T13:33:54.797609Z

?

Gregory Bleiker 2025-11-23T13:34:28.993059Z

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

borkdude 2025-11-23T13:36:35.951199Z

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

borkdude 2025-11-23T13:38:21.255769Z

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
Gregory Bleiker 2025-11-23T13:39:50.252529Z

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)

      "])

borkdude 2025-11-23T13:40:55.638199Z

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

borkdude 2025-11-23T13:41:29.364389Z

#scittle

Gregory Bleiker 2025-11-23T13:42:16.693549Z

I'll have another think about it

Chris McCormick 2025-11-23T14:15:57.756859Z

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

Chris McCormick 2025-11-23T14:17:20.883559Z

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)])

Chris McCormick 2025-11-23T14:18:32.757909Z

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

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

Gregory Bleiker 2025-11-23T20:09:55.555729Z

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