Fork me on GitHub
#scittle
<
2022-09-21
>
leobm09:09:06

@borkdude thanks, I already thought of something similar, just doesn't make the code very nice. Thanks anyway. The this-as macro I had also seen in clojurescript, thought maybe I could somehow implement this macro myself in skittle (but I haven't really written macros myself yet and in SCI it seems to work a bit differently somehow). I'm also not sure if this macro could be implemented in SCI or skittle at all.

borkdude09:09:41

scittle is spelled with a c, not a k. Why does everybody spell it with a k... you're not the first one this week :)

leobm09:09:49

ohhh sorry

borkdude09:09:05

no problem, just wondering why people do this 😆

teodorlu11:09:51

Skittles sounds like a tasty piece of chocolate 🍫 Isn't there something called "skittles"?

leobm09:09:27

no idea 😂 maybe because I'm german

borkdude09:09:14

unfortunately this-as isn't easy to implement in SCI because SCI is an interpreter, not a compiler. In a compiler it's much easier to implement this-as since you can just emit (let [x this] ...) basically, but in SCI this isn't as easy

leobm14:09:45

I have tried the following yet now. This works, what do you think?

(defn object [p ms],
  (js/scittle.core.eval_string
   (str `(let [this ~p]
           ~@(for [[k m] ms]
               `(aset this (name ~k) ~m))
           this))))

(defn Foo []
  (object
   #js {:x 1
        :y 2
        :z 20}
   {:test `(fn [] (.-z this))}))

borkdude14:09:46

You could maybe also do this using a macro.

(defmacro do-with [[obj binding] & body]
  `(let [~binding obj] ~@body ~binding))

(do-with [this #js {:a 1}] (set! (.-foo this) (fn [] (.-z this))))
;;=> #js {:a 1 :foo ...}  

borkdude14:09:08

There is also the doto macro in clojure which you could maybe use

borkdude14:09:13

but yeah, that seems like a good approach

borkdude14:09:25

If you can, you should try to avoid eval by writing a macro

leobm14:09:36

ok, thanks

leobm09:09:16

that's why i didn't find the channel yesterday. that's why i asked my question in babashka.

borkdude09:09:22

Perhaps it's possible, feel free to look into this

leobm09:09:03

ok, I'll probably have to spend more time with SCI. But your projects are really ingenious. Very great work from you.

❤️ 1
genRaiy10:09:53

skittle ... a popular brand of sweets also things you throw balls at

Benjamin10:09:06

<script crossorigin src=""></script>
    <script crossorigin src=""></script>
When I try this and open my html file with a browser I get CORS policy error. What is the best way to include those scripts?

borkdude10:09:00

do you serve the file via a server or via the file system?

Benjamin10:09:37

my html file is filesystem

borkdude10:09:28

try a server:

bbin install io.github.babashka/http-server 

Benjamin10:09:18

[benj@benj-pc scittle-prints-itself]$ [benj@benj-pc scittle-prints-itself]$ http-server --help
Cloning: 
Error building classpath. Unable to clone /home/benj/.gitlibs/_repos/ssh/github.com/babashka/sci.nrepl.git
: Permission denied (publickey).
looks wrong. I'm guessing this is a tools issue ah lol it's because I have something wrong at bb.edn in the directory I think

borkdude10:09:13

hmm, I don't know what this is... @U0CLCL6T0 an idea?

borkdude10:09:28

you could also use http-server directly without going through bbin

Benjamin10:09:52

but it was that I had in bb.edn

Benjamin10:09:57

that was the issue

Benjamin10:09:34

it's just that bb pulls stuff with clj-tools when you invoke in the dir with bb.edn. And then I was confused because no connection to http-server