Fork me on GitHub

is it possible to add the clojurescript this-as macro in sci (in the browser?

(.onCancel "onCancel called" (fn [text] 
                                     (this-as this
                                       (.setText this text)
                                       (.remove this))))
I am trying to call some functions on js objects.


@hoertlehner Can you make a full example? This-as is difficult to support in SCI, but I think you can make a workaround similar to this:

(def obj
  (let [obj #js {:text "foo"}
        setText (fn [text] (set! (.-text obj) text))
        getText (fn [] (.-text obj))]
    (set! (.-setText obj) setText)
    (set! (.-getText obj) getText)

(.setText obj "hello")
(prn (.getText obj)) ;; "hello"


> The problem here is that parse-long isn't available in every version of clojure, so we'd have to backport it since SCI supports clojure 1.9+. Alternatively you can just add it yourself in {:namespaces {'clojure.core {'parse-long ...}}} (edited) > > Similar for clojure.math. This has been added in babashka > but not in SCI > One other concern is that everything added to namespaces will be part of the JS bundle so going forward I think I won't add anything new there if it wasn't already in 1.9-1.10 but provide ways to optionally include it (edited) > Maybe we can have an optional addon namespace which provides 1.11 features and one for clojure.math too > > so you can load those when you're on clojure 1.11 My use case was on Scittle - so I realized that I would need to be on a recent version of cojurescript too. It wasn't entirely clear to me which version of Sci Scittle was compiled against. Asking in #scittle would perhaps be better. Inlining the function also works. In general, good points about backwards compatibility. We don't know which version of Clojure we're running on in advance. Perhaps moving a bit slowly makes sense here. Being able to manually configure the namespace maps is a good solution when I know that I have the function available on the host.


scittle is compiled using shadow-cljs and it uses whatever shadow-cljs brings along

👍 1

once shadow-cljs "enables" the function, we can bring it in

👍 1

Ah, right, so we can solve this in scittle, no changes required in sci? Perfect 😄


Howdy borkdude, have you come across openjdk project in your travels? It seemed up your street, I was wondering if you'd tried it out? thinking-face


Thanks. I haven't tried. I think #nextjournal has experimented with CRIU in the past / cc @U5H74UNSF