Fork me on GitHub
#cherry
<
2023-05-16
>
Jakub Šťastný13:05:21

Hey @borkdude, is there any reason you could think of why both of these statements[1] prints out the same thing, which is a Clojure object? Could the clj->js conversion be broken? [1]:

(js/console.log "CLJ" result)
(js/console.log "JS" (clj->js result))      

borkdude13:05:08

please make a smaller repro with result being explicit?

Jakub Šťastný13:05:12

Note that it typically works, just in this one case it doesn't

Jakub Šťastný14:05:08

@borkdude OK it's something to do with the transducer:

(defn empty-transducer [xf]
  (fn
    ([] (xf))
    ([acc input] acc)
    ([result] result)))

(js/console.log "Empty" (clj->js (into [] empty-transducer data)))
This still logs a CLJS object. Let me see if I can replicate out of the project, but essentially, it's got to do with the transducer.

borkdude14:05:41

and does it work in regular CLJS?

borkdude14:05:46

or in #C029PTWD3HR?

Jakub Šťastný14:05:19

No idea – yet.

borkdude14:05:19

$ npx nbb
Welcome to nbb v1.2.173!
user=> (defn empty-transducer [xf]
  (fn
    ([] (xf))
    ([acc input] acc)
    ([result] result)))

(js/console.log "Empty" (clj->js (into [] empty-transducer data)))#'user/empty-transducer
user=> (js/console.log "Empty" (clj->js (into [] empty-transducer data)))

borkdude14:05:31

please specify an example without any free variables

Jakub Šťastný14:05:42

(defn empty-transducer [xf]
  (fn
    ([] (xf))
    ([acc input] acc)
    ([result] result)))

(js/console.log "Empty" (clj->js (into [] empty-transducer [])))

Jakub Šťastný14:05:50

Just with an empty array.

borkdude14:05:12

works the same in nbb, a CLJS data structure is logged

borkdude14:05:31

The type seems to be an Empty

borkdude14:05:08

ah it's a TransientVector actually

borkdude14:05:21

I think your reducing function should still call persistent!?

borkdude14:05:51

or there is a bug in CLJS, could be

Jakub Šťastný14:05:12

OK that's the first time I'm hearing about persistent!.

(defn empty-persistent-transducer [xf]
  (fn
    ([] (xf))
    ([acc input] acc)
    ([result] (persistent! result))))
This works.

Jakub Šťastný14:05:27

Can't see much documentation about what it actually does though.

borkdude14:05:27

it turns a transient object into a persistent one

Jakub Šťastný14:05:15

OK not sure what that means, but hey, it works, I fixed the code where I had the original problem. Thanks!

Jakub Šťastný20:05:16

Another thing @borkdude, I see Cherry's got macro support in its goals, but there's nothing more in the README about macro support. Are these supported yet in any way? I'd like to do (defmacro inline-resource [path] (slurp path)) if it's available.

borkdude21:05:58

@U024VBA4FD5 It's possible to use (:require-macros [my-macros :refer [inline-resources]) but this is very limited ATM. The macro namespace must live under the src directory as a .cljc file. When you're running cherry with Node.js the macro namespace will also be executed in node

Jakub Šťastný21:05:58

That's a good news. Thanks.

borkdude21:05:34

At least this is how it worked in #C03U8L2NXNC but not sure if I ported this to cherry... I can check tomorrow

Jakub Šťastný21:05:28

I'm going to have a go at it in a few mins, I'll shout if it's broken 😄

Jakub Šťastný21:05:12

It looks like it's working, generally, but I'm getting Error: Could not resolve symbol: slurp. • https://github.com/BizMentorAI/nace-lookup/blob/master/src/macros.cljchttps://github.com/BizMentorAI/nace-lookup/blob/master/src/workers/autocomplete/autocomplete.cljs#L5 Is that a known issue (missing slurp)? Is there a workaround?

Jakub Šťastný21:05:30

I know Cherry's experimental, but really so far it works great so I want to keep using it. It's much easier to reason about for me and the fact that it doesn't need nearly 1GB of MEM is pretty important to me.

borkdude21:05:55

yes, in CLJS/node slurp is not available, so you can use (:require ["fs" :as fs]) + fs/readFileSync