sci

phronmophobic 2024-09-11T18:50:45.276809Z

I have {:classes {:allow :all}} in my sci opts which works on the jvm, but seems to disappear when compiled under native image. Does {:classes {:allow :all}} behave differently under native image compilation?

deepbit 2024-09-29T13:13:48.103179Z

Hello, I was working on a project using klipse, and I could use async funcs like go in the editor, now I am trying to switch to an editor based on babashka/sci and I was trying to bind cljs.core.async namespaces to use go and the other functions but it doesn't seem to work? any clue how to achieve that? thanks

borkdude 2024-09-29T13:42:14.140309Z

@deepbit this question seems a bit out of place in this thread, but the short answer is: don't even try to go there and just expose promesa.core instead

borkdude 2024-09-29T13:43:07.443379Z

the core.async go macro is a highly complex macro which uses tools.analyzer under the hood, which doesn't work in SCI currently

borkdude 2024-09-29T13:43:27.406969Z

well, maybe it does now, but it's a big hassle for almost no benefits compared to just using promises

deepbit 2024-09-29T14:59:52.432689Z

Oops, I'm very sorry I didn't realize I added the message to the thread, my bad!! Thanks for the answer though.

borkdude 2024-09-29T15:01:51.701609Z

if you're interested in promesa, you can obtain a SCI configuration here: https://github.com/babashka/sci.configs and view the demo here: https://babashka.org/sci.configs/

deepbit 2024-09-29T15:18:41.068849Z

Thanks that is very useful, I'll give it a go, it might save my project 😄

borkdude 2024-09-29T15:19:26.934929Z

do you have your previous demo online somewhere?

deepbit 2024-09-29T15:29:12.984159Z

So I've got an online version using klipse + core async, and in this case I should translate it to SCI + promesa, I think it is possible, it is quite a complicated issue. Basically I am writing a coding framework like https://code.org/minecraft for kids, but instead of using blockly, using written clojure. And I don't want kids to have to deal with async and js execution model, so I use macros to rewrite their code so that if feel synchronous using channels, I guess with promesa I could do similar, need to investigate a bit more. A still work in progress example is in here https://coelias.github.io/juliaworld/ If you type (forward) (forward) it moves forward twice but actually the code is rewritten so that it seem synchronous. The macros are written in the HTML source actually laughcry . I had many issues with Klipse but I managed to get what I wanted working. btw I am feeling bad for keeping adding to this thread

borkdude 2024-09-29T15:32:13.395639Z

also reminds me of https://2.maria.cloud/ which was ported from self-hosted CLJS to SCI

borkdude 2024-09-11T18:51:36.957169Z

It doesn't but you also need to provide native image with reflection configuration for it to work

borkdude 2024-09-11T18:52:02.670649Z

not sure what you meant with "disappear"

phronmophobic 2024-09-11T18:53:29.290219Z

I do have the reflection configuration. When I print

(-> @sci-ctx
             :env
             deref
             :raw-classes
             keys)
I can see :allow as one of the keys on the JVM, but it's not included when I print it under native image compilation

phronmophobic 2024-09-11T18:54:57.970339Z

The error I'm getting is:

clojure.lang.ExceptionInfo: Method close on class java.io.BufferedInputStream not allowed! pod *cider-repl examples/app:192.168.0.182:23456(clj)*:1:1
rather than NoSuchFieldException.

borkdude 2024-09-11T18:55:24.825719Z

do you have a repro

borkdude 2024-09-11T18:55:43.567359Z

wait

borkdude 2024-09-11T18:56:31.768269Z

I think I've never used this in native-image since I prefer this message to what graalvm had (an NPE or something) way back

borkdude 2024-09-11T18:56:36.674969Z

but perhaps this changed

phronmophobic 2024-09-11T18:57:53.364909Z

I can repro it, but my setup is very complicated at the moment. I was hoping there was a known thing I was probably doing wrong.

phronmophobic 2024-09-11T18:58:19.463679Z

I'll try to dig into it a bit more

borkdude 2024-09-11T19:00:23.101809Z

probably a bug that I haven't ran across since I've never done this

borkdude 2024-09-11T19:00:46.906629Z

feel free to post an issue, I can check tomorrow-ish

phronmophobic 2024-09-11T19:02:13.768209Z

awesome! Thank you!

borkdude 2024-09-11T19:03:16.531889Z

I'm not sure why SCI would behave differently under native-image though

borkdude 2024-09-11T19:03:40.166169Z

I mean, there's not a conditional that checks whether we're on native image and then deletes that key or something

phronmophobic 2024-09-11T19:04:09.788709Z

Yea, I've been staring at the code and can't figure it out either.

borkdude 2024-09-11T19:04:41.615089Z

do you do anything to the ctx yourself outside of the supported sci.core API?

phronmophobic 2024-09-11T19:04:56.779939Z

I'm in the process of logging every step along the way to see if I can narrow down where something might happen.

phronmophobic 2024-09-11T19:05:34.739989Z

I start the nrepl server, but the :allow key seems to be missing from the environment before I start the server.

borkdude 2024-09-11T19:08:51.261969Z

you could try to mess a little with sci.impl.main

borkdude 2024-09-11T19:09:00.359689Z

because that's a fairly small SCI program

borkdude 2024-09-11T19:09:07.940879Z

which you can compile with script/compile in SCI I think

borkdude 2024-09-11T19:09:20.894409Z

that's what I would do tomorrow-ish

phronmophobic 2024-09-11T19:09:36.052379Z

ah ok cool. I'll give that a try.

phronmophobic 2024-09-11T19:31:54.329829Z

picard-facepalm So the problem was that I was calling:

(sci/eval-string (slurp path) @sci-ctx))
instead of
(sci/eval-string* @sci-ctx (slurp path)))
This was overriding the env.

phronmophobic 2024-09-11T19:32:20.883239Z

Anyway, everything is working now!

borkdude 2024-09-11T19:43:36.816269Z

aaah ok!