Fork me on GitHub
#sci
<
2024-02-02
>
mynomoto10:02:22

A port of Clojurescript Koans using SCI. Thank you, @borkdude, to make that possible. gratitude

borkdude10:02:38

Amazing work, thank you

mynomoto11:02:13

I have a confession, I tried to change as little as possible, so I first attempted to use self-hosted Clojurescript. But after trying to make it work using an updated Clojurescript and shadow-cljs I gave it up and decided to port to SCI. It took less time to convert to SCI than the time I used to try to use self-hosting. Also, I can use advanced compilation, and the SCI version is way smaller than the Clojurescript one. SCI is an incredible tool.

borkdude11:02:35

great to hear. there's another option emerging for this kind of use case, it's the cherry compiler that can be embedded: https://github.com/squint-cljs/cherry/blob/main/doc/embed.md but it's less mature than SCI (simply because it's newer) - the only benefit of that is better performance (which should not matter for a tool that teaches how to use Clojure)

mynomoto11:02:05

More options are great! I will check it out, but the current bundle size is enough, so I will probably keep on the more mature tool. Does SCI track clojure or clojurescript when there are different behaviors? I found some differences from clojure while I was writing some lessons on another project.

borkdude11:02:54

SCI doesn't track clojure or clojurescript unless there are new behaviors like the one with keyword arguments vs passing a map. This is so that SCI can be used with older version of Clojure as well. Right now it supports 1.9

borkdude11:02:08

Which differences with Clojure did you find?

mynomoto11:02:43

Only corner cases, like calling max without arguments. Cases where Clojure returns exceptions, I think. I haven't checked the Clojurescript behavior yet to confirm that it is the same.

borkdude11:02:57

The max function isn't re-implemented so that would surprise me

borkdude11:02:20

$ bb -e '(max)'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ArityException
Message:  Wrong number of args (0) passed to: clojure.core/max

borkdude11:02:21

The CLJS version only throws because max in call position is implemented using a macro. What happens in SCI is more like:

plk -e '(let [m max] (m))'

borkdude11:02:24

which doesn't throw

mynomoto11:02:28

Let me pick a real one instead of trying to use my memory 😅

mynomoto11:02:35

subs throws in clojure with index out of bounds when using an index larger than the string size.

borkdude11:02:06

also not re-implemented. it's probably just a CLJS vs CLJ difference

mynomoto11:02:59

Ok, so when are cases like this it should behave like Clojurescript except when there is a macro implementation?

borkdude11:02:21

yes, test it like: (let [f subs] (f ...))

borkdude11:02:00

btw in CLJS:

$ plk -e '(subs "" 0 11)'
""

borkdude11:02:51

of course if you wanted to, you could override subs in clojure.core with your own:

{:namespaces {'clojure.core {'subs ...}}}
`

mynomoto11:02:11

Yeah, I suspected that was the case (that it behaved like in cljs). Thank you, I need to think if I would go that far, not really sure if it is necessary. I would just show an example throwing, so the user would not be surprised when it happened. There will be other exceptions that I can use 😉