clojurescript

Amin 2025-04-04T10:06:54.743129Z

Hi all, I鈥檓 in the process of learning clojure and clojurescript, as part of that I鈥檓 implementing tetris https://github.com/alamqadem/tetris-clj. So far, I鈥檝e set up a clojure project with lein and I am able to play it in a terminal. Now, I would like to reuse the same code for a cljs project and have the graphical interface in the browser, but keep at the same time also the ability to run it in the terminal. Would it be possible for the same project to be a clojure project and cljs project? Btw, if you have a beginner guide on how to get started with cljs and set up a repl, I would really appreciate it.

p-himik 2025-04-04T10:11:38.103089Z

> Would it be possible for the same project to be a clojure project and cljs project? Yes. of course. Everything that's common can be put in .cljc files - those are read by both CLJ and CLJS. Everything that differs can be either put in their own .clj/`.cljs` files or inside so-called reader conditionals in .cljc files.

馃檶 1
Melody 2025-04-04T16:45:45.763049Z

What editor are you using? Do you have a specific question about the repl/are you encountering a particular issue? Here is the cider manual if you are using emacs https://docs.cider.mx/cider/1.17/ https://www.youtube.com/watch?v=aYA4AAjLfT0 Hopefully one of these videos might be helpful: https://www.youtube.com/watch?v=gIoadGfm5T8 https://www.youtube.com/watch?v=7muHVkxzZcE https://www.youtube.com/watch?v=VbIawuoYAVY https://www.youtube.com/results?search_query=clojurescript+sets

DrLj贸tsson 2025-04-04T11:58:13.412239Z

What is the effect of adding ^js to destructuring? For example (fn [{:keys [^js foo ^js bar]}] ,,,)

p-himik 2025-04-04T12:00:11.060289Z

Should be the same as if you introduced a symbol like (let [^js foo (get args :foo)] ...).

DrLj贸tsson 2025-04-04T12:01:06.653499Z

And what is the effect of that...? I haven't quite grasped the purpose of ^js

p-himik 2025-04-04T12:02:26.411969Z

Same but in the vanilla CLJS docs: https://clojurescript.org/guides/externs#externs-inference Note that ^js/Something is functionally fully equivalent to just ^js.

DrLj贸tsson 2025-04-04T12:03:23.768649Z

This is from code that I haven't written myself. But I have full control over the :foo and :bar keys and the argument is a regular cljs map. So is there any need for ^js?

DrLj贸tsson 2025-04-04T12:04:05.932549Z

The values for these keys are DOM elements

p-himik 2025-04-04T12:09:36.164439Z

For DOM elements there should be no need for ^js unless, I think, the CLJS function uses some very new DOM API that's not a part of the built-in externs.

p-himik 2025-04-04T12:10:02.520939Z

But ^js also won't hurt here and might serve as documentation of sorts.

DrLj贸tsson 2025-04-04T12:10:15.447289Z

Thanks!

馃憤 1
DrLj贸tsson 2025-04-04T16:58:53.453719Z

Still trying to grasp this. I assume that keywords are never renamed? So the interpretation is that in (.field foo), .field will not be renamed? foo from the original example.

p-himik 2025-04-04T16:59:16.907479Z

Yes.

DrLj贸tsson 2025-04-04T16:59:38.274209Z

Get it!