sci

awb99 2022-04-20T04:10:02.519449Z

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.

borkdude 2022-04-20T07:30:55.199529Z

@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)
    obj))

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

borkdude 2022-04-20T09:03:56.707709Z

@hoertlehner I documented this workaround here: https://github.com/babashka/sci#this-as

awb99 2022-04-20T17:57:53.962539Z

thanks a lot @borkdude

teodorlu 2022-04-20T10:33:35.053219Z

> 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.

borkdude 2022-04-20T18:54:24.090489Z

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

👍 1
borkdude 2022-04-20T18:54:35.099989Z

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

👍 1
teodorlu 2022-04-20T19:02:50.871289Z

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

borkdude 2022-04-20T19:03:25.815239Z

yes

💯 1
2022-04-20T23:16:50.788139Z

Howdy borkdude, have you come across https://foojay.io/today/introducing-the-openjdk-coordinated-restore-at-checkpoint-project/ openjdk project in your travels? It seemed up your street, I was wondering if you'd tried it out? thinking-face

borkdude 2022-04-21T07:23:43.364529Z

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