cherry

2023-05-16T13:31:21.366019Z

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))      

borkdude 2023-05-16T13:33:08.552519Z

please make a smaller repro with result being explicit?

2023-05-16T13:33:12.815979Z

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

2023-05-16T13:33:32.740129Z

Yes I'll try.

2023-05-16T14:36:08.760529Z

@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.

borkdude 2023-05-16T14:36:41.568029Z

and does it work in regular CLJS?

borkdude 2023-05-16T14:36:46.734409Z

or in #nbb?

2023-05-16T14:37:19.203369Z

No idea – yet.

borkdude 2023-05-16T14:37:19.906939Z

$ 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)))

borkdude 2023-05-16T14:37:31.706389Z

please specify an example without any free variables

2023-05-16T14:39:42.507269Z

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

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

2023-05-16T14:39:50.862539Z

Just with an empty array.

borkdude 2023-05-16T14:40:12.579499Z

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

2023-05-16T14:40:31.368379Z

Yep.

borkdude 2023-05-16T14:40:31.552959Z

The type seems to be an Empty

borkdude 2023-05-16T14:41:08.196979Z

ah it's a TransientVector actually

borkdude 2023-05-16T14:41:21.917069Z

I think your reducing function should still call persistent!?

borkdude 2023-05-16T14:41:51.895799Z

or there is a bug in CLJS, could be

2023-05-16T14:46:12.572129Z

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.

2023-05-16T14:46:27.438159Z

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

borkdude 2023-05-16T14:48:27.432449Z

it turns a transient object into a persistent one

2023-05-16T14:53:15.490299Z

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

borkdude 2023-05-16T14:54:37.995579Z

👍

2023-05-16T20:57:16.263199Z

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.

borkdude 2023-05-16T21:15:58.193309Z

@jakub.stastny.pt_serv 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

2023-05-16T21:16:58.034429Z

That's a good news. Thanks.

borkdude 2023-05-16T21:18:34.771819Z

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

2023-05-16T21:19:28.399349Z

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

2023-05-16T21:35:12.520989Z

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?

2023-05-16T21:37:30.235809Z

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.

borkdude 2023-05-16T21:40:55.792779Z

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

2023-05-16T21:41:32.208589Z

Right, got it.