sci

https://github.com/babashka/SCI - also see #babashka and #nbb
2020-07-16T13:52:28.263400Z

I’m using to using Sci to render some html via re-agent in clojurescript. Most of the things work fine. One of the things that don’t work is using println in a callback:

[:a {:href "#" :on-click (fn [] (println "hello") )}]
In the browser console I can see:
react-dom.inc.js:481 Uncaught cljs$core$ExceptionInfo {message: "cljs.core.deref.call(...).append is not a function [at line 12, column 19]", data: {…}, cause: TypeError: cljs.core.deref.call(...).append is not a function
    at Function.cljs$core$IFn$_invoke…, name: "Error", description: undefined, …}
I’m guessing the *out* value has not been forwarded. Any suggestion here?

2020-07-16T14:08:44.264100Z

Ok i’m getting it also in other contexts not specifically related to the click handler. I’ll do some more research

2020-07-16T14:21:17.265100Z

When I define println as a binding it works like I expected. Maybe there is a better with sci/binding

borkdude 2020-07-16T16:52:01.266200Z

@jeroenvandijk println et al. work when you bind sci/out to *out*. by default it's not bound to anything as to not let users cause unwanted side effects

borkdude 2020-07-16T16:52:33.266400Z

See https://github.com/borkdude/sci#stdout-and-stdin

borkdude 2020-07-16T16:58:11.267100Z

I guess the mechanics of *out* are different in CLJS, so overriding println makes sense there

2020-07-16T17:21:15.267300Z

I guess it would have to be something similar to (enable-console-print!) , but I’ll stick with overriding println for now. Thanks!

borkdude 2020-07-16T17:23:27.267500Z

In CLJS *print-fn* is used for this. Maybe sci should adopt sci/*print-fn* for the CLJS api, not entirely sure about this...

borkdude 2020-07-16T17:24:08.267800Z

I'll make an issue as a reminder

2020-07-16T17:24:38.268Z

ok cool. I don’t really have an idea here. I can work with the current situation

borkdude 2020-07-16T17:24:50.268200Z

:thumbsup:

borkdude 2020-07-16T17:25:00.268400Z

it's just for debugging I presume?

2020-07-16T17:25:09.268600Z

yeah

borkdude 2020-07-16T17:25:44.268800Z

Chlorine also uses sci to render stuff using reagent, I believe

2020-07-16T17:25:57.269Z

ah cool, i’ll check

2020-07-16T17:27:30.269200Z

I’m pretty surprised in what Sci is able to do in combination with re-agent. only things like (set! …) seem to be out of bounds

borkdude 2020-07-16T17:28:14.269400Z

what happens when you do that?

2020-07-16T17:34:07.269600Z

the first is when i define set! via a binding. The second is when i define nothing

2020-07-16T17:34:42.270200Z

a work around is using (aset (js/FileReader.) "onload" (fn [] …)) in this case

borkdude 2020-07-16T17:40:50.270400Z

why did you need to re-define set!?

2020-07-16T17:41:54.270600Z

because of the second screenshot. That happens when i don’t define it

2020-07-16T17:42:36.270800Z

No protocol method IBox.getVal defined for type cljs.core/Cons: (. file-reader "-onload" nil)

borkdude 2020-07-16T17:42:58.271Z

aha, might be worth an issue I think

2020-07-16T17:43:23.271200Z

Yeah I don’t fully understand what’s happening there. I guess it’s an interop thing

borkdude 2020-07-16T17:44:59.271400Z

I think set! has only been implemented to set values on dynamic vars in sci

nahuel 2020-07-16T18:31:24.272300Z

can you make sci interpret an expression step by step?

nahuel 2020-07-16T18:33:39.274Z

I saw https://github.com/JuliaDebug/JuliaInterpreter.jl is used to develop a debugger for Julia, seems like an interesting approach. I saw an issue in sci github about limiting the execution by time, but not by number of steps (or reductions in Erlang parlance). Also, can you execute an step and then resume the execution?

borkdude 2020-07-16T18:56:07.275100Z

I’m currently having an internet problem and aren’t able to do anything from a laptop.

borkdude 2020-07-16T19:27:12.276100Z

Ah, it seems to work now again. The limiting of execution steps or time (both are still up for discussion) are a solution for the problem of hanging evaluations. I've never considered implementing a debugger with sci so far.

borkdude 2020-07-16T19:31:56.276200Z

@jeroenvandijk I think the recommended API for setting and getting object fields in CLJS is the goog.object namespace

borkdude 2020-07-16T19:32:19.276400Z

So you could try adding that to your sci config

borkdude 2020-07-16T19:34:48.276600Z

Having said that, I made an issue here: https://github.com/borkdude/sci/issues/366

nahuel 2020-07-16T19:41:16.279Z

being capable of resuming execution after limiting by steps/time can open a nice door to implement killable actors like in erlang using sci, for some usages can be nicer than core.async. Also it will be nice to being able to yield from sci interpreted code.

💯 1
2020-07-16T19:41:58.279100Z

Thanks! I think you are right. I’m porting some cljs app to something in Sci. These are examples of the things I come across. I need to pick my battles in order to make some progress. For now I chose not use the filereader part :)

borkdude 2020-07-16T20:14:53.280700Z

@nahuel that is interesting, I'll have to keep that in the back of my mind for some time