sci

https://github.com/babashka/SCI - also see #babashka and #nbb
mkvlr 2020-11-25T09:02:59.129500Z

is ctx in sci a mutable thing? It’s stored in an atom here https://github.com/babashka/xterm-sci/blob/a8e16f35a2b77a006b64f90e5a40f3a39e3c9f94/src/xterm_sci/core.cljs#L28 but I can’t see where it’s being reset!?

borkdude 2020-11-25T09:04:00.130500Z

yes, ctx is mutable and eval-string will mutate it

mkvlr 2020-11-25T09:04:33.131400Z

ok, any reason for storing it in an atom?

borkdude 2020-11-25T09:05:57.132200Z

in that code it might not be needed

borkdude 2020-11-25T09:06:12.132500Z

there are reasons to do this, if you e.g. use functions in the opts that need the ctx, so you will have a circular dependency. I often use a volatile for this

borkdude 2020-11-25T09:07:00.132900Z

but in this specific example, I think you could get rid of the atom

mkvlr 2020-11-25T09:07:33.133200Z

ok thanks

mkvlr 2020-11-25T09:08:13.133900Z

and setting :classes {'js goog/global} should make js/ work just like in bootstrap cljs?

borkdude 2020-11-25T09:09:21.135800Z

it works to a degree, but it's best to write some tests for that to verify the details of that. I'm not an expert in CLJS interop :)

borkdude 2020-11-25T09:09:49.136500Z

The example is hosted here, so you can try: https://babashka.org/xterm-sci/

mkvlr 2020-11-25T09:09:59.136700Z

I was confused at first that js/window interpreted in sci is the same as a bining {'js-window js/window} but that’s probably because I don’t understand dynamic scope

mkvlr 2020-11-25T09:10:20.137Z

I checked that it is the same window…

borkdude 2020-11-25T09:11:02.137300Z

sorry, I don't understand your message about js-window

mkvlr 2020-11-25T09:12:16.137600Z

not sure I do, given the opts {:classes {'js js/window} :bindings {'js-window js/window}}

mkvlr 2020-11-25T09:12:38.137900Z

(= js-window js/window) evalutates to true

mkvlr 2020-11-25T09:13:29.138700Z

I guess this is more a js question

mkvlr 2020-11-25T09:14:15.139500Z

I don’t get what all those windows are, but it seems to work

😄 1
borkdude 2020-11-25T09:14:56.140100Z

is js-window a thing in CLJS? why have you given it that name?

borkdude 2020-11-25T09:15:37.140700Z

@mkvlr you can also mock out all the objects you want to give access to like this: https://github.com/borkdude/sci/blob/c2045f5e56f6c52f05921eaff9d70d64ac971c98/test/sci/interop_test.cljc#L94

mkvlr 2020-11-25T09:15:54.141200Z

yep, but I want all of js/

borkdude 2020-11-25T09:17:29.141700Z

so maybe then this is the best option: https://github.com/babashka/xterm-sci/blob/a8e16f35a2b77a006b64f90e5a40f3a39e3c9f94/src/xterm_sci/core.cljs#L17

mkvlr 2020-11-25T09:17:47.142100Z

yep, that’s what I’m doing

borkdude 2020-11-25T09:18:15.142500Z

then you don't need this right? :bindings {'js-window js/window} - that's the part I'm confused about

mkvlr 2020-11-25T09:18:41.142900Z

no, this was just for testing that js/window interpreted returns the right thing

borkdude 2020-11-25T09:18:46.143100Z

ok

mkvlr 2020-11-25T09:22:41.143400Z

TIL

borkdude 2020-11-25T09:27:25.144100Z

I notice this works in cljs:

cljs.user=> js/location.href
"<http://localhost:1339/>"
but in sci this currently doesn't:
user=&gt; js/location.href
nil
user=&gt; (.-href js/location)
"<https://babashka.org/xterm-sci/>"
user=&gt; 

borkdude 2020-11-25T09:28:25.144600Z

If you want to allow everything, you will probably also need to add: https://github.com/babashka/xterm-sci/blob/37bd9bceb38c1e76a40ce584fc2b4fbdc201bd36/src/xterm_sci/core.cljs#L18

mkvlr 2020-11-25T09:35:05.145700Z

right, same for e.g. (.-body js/document) (works) vs js/document.body (returns nil)

borkdude 2020-11-25T09:37:34.146300Z

I think we can fix this in sci, but I'm not sure if js/document.body is officially supported by CLJS (although it obviously works)

borkdude 2020-11-25T09:37:52.146600Z

if there are any official docs for this, I will consider a fix

mkvlr 2020-11-25T09:39:07.146800Z

I’ll see if I can find them

mkvlr 2020-11-25T09:39:42.147300Z

is there a way to support the #js reader tag currently?

borkdude 2020-11-25T09:40:38.147700Z

I think that should already be supported by default in sci. It doesn't work for you?

borkdude 2020-11-25T09:41:52.148Z

hmm, it's returning something weird:

user=&gt; #js [1 2 3]
#object[JW [object Object]]

borkdude 2020-11-25T09:42:26.148200Z

this does work:

user=&gt; (clj-&gt;js [1 2 3])
#js [1 2 3]

borkdude 2020-11-25T09:42:33.148400Z

Feel free to post issues about this

mkvlr 2020-11-25T09:45:13.148800Z

will do thanks

borkdude 2020-11-25T09:56:46.148900Z

borkdude 2020-11-25T10:20:11.149500Z

thanks

mkvlr 2020-11-25T13:19:47.151400Z

@borkdude I see you fixed this already in sci, thank you! Is there a prerelease jar I can grab somewhere already?

borkdude 2020-11-25T13:20:17.151700Z

@mkvlr you can use it as a git dep if you're using deps.edn?

mkvlr 2020-11-25T13:20:25.152Z

oh yes I am

mkvlr 2020-11-25T13:20:35.152300Z

will do, thanks!

borkdude 2020-11-25T13:20:40.152500Z

I'm also doing that in the sci xterm project