clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-06-22T00:07:20.476200Z

Is there any recommended Java runtime/version for CLJS? I installed openjdk-16-jre-headless, I'm on Ubuntu. Running yarn build with shadow-cljs takes 65.12s user 1.44s system 99% cpu 1:06.97 total. Is that normal? It's a hello world app, generated by yarn create cljs-app, the react-start-app alternative for CLJS if I understand it correctly. And I'm running out of memory with yarn start pretty much immediately. OK, my server is very basic, it's an AWS EC2 free micro instance, so it's got only 1 GB of RAM. I added additional 2.5 GB of swap, but it'd cause exception saying it run out of memory without touching the swap much. And there's NOTHING else running on it. That feels weird to me. Is it really THAT slow or is it just OpenJDK? Should I be using different Java?

Apple 2021-06-22T11:00:50.477700Z

Is AWS EC2 free micro instance performant? the oracle cloud equivalent is probably similar in performance and it is not very good for development.

2021-06-22T16:20:06.480200Z

Slack failed me on notifications here. Looking into it now!

2021-06-22T16:23:09.484500Z

@zengxh so I just switched to CJ. Before I was using Ruby/Node.js/Deno, ocassionally Common Lisp, Elm etc. and it was never an issue. Using Emacs and Mosh (rather than plain SSH), all works without any lags or delay. Of course JVM (and Graal even more so), are pretty hungry beasts, so I do not know if it's performant enough. I will do my best to stick to it, would rather not spend any extra money – I'm not working at the moment. (But it's likely that JVM will leave me with no other choice, but let's first give it a go.)

2021-06-22T16:28:07.487500Z

@zengxh you said in another thread that the Oracle cloud offers more memory than AWS (although it might have been a typo? I kinda think it was.) All I found for the free tier of the Oracle cloud was 2 Compute VMs, each with 1/8 OCPU and 1 GB memory. I suppose that's all Oracle gives you, isn't it? Still it looks better than AWS, as it's unlimited vs. 1 year, so I might switch ... but it doesn't solve the problem with the memory though.

2021-06-22T16:34:13.488500Z

@thheller man that fixed it! Thanks so much!! 600 MB did the trick. Now it seems to work pretty smooth.

Apple 2021-06-22T16:37:23.488700Z

https://www.oracle.com/cloud/free/#always-free 4 Arm-based Ampere A1 cores and 24 GB of memory usable as one VM or up to 4 VMs.

👍 1
thheller 2021-06-22T05:57:43.477Z

you can tweak the memory by setting :jvm-opts ["-Xmx700m"] in shadow-cljs.edn (max 700mb of ram). build times pretty much depend on what you are building and it should only be that slow once. after that the cache should kick in and make things much faster.

thheller 2021-06-22T05:58:32.477300Z

you can go lower with memory settings but going too low can make things slower. 500m is usually fine

vemv 2021-06-22T15:31:04.479600Z

Is there a linter for ensuring that each ns having deftests is included in a given project's cljs.test/run-tests call? Have always wanted that

Patrick Tu 2021-06-22T16:49:02.489600Z

Absolute beginner here, first day with ClojureScript. Stuck on this

Patrick Tu 2021-06-23T10:43:45.496400Z

Haha what a lot to unpackage!

jeffmad 2021-06-25T03:49:10.016400Z

you have a talent for clear, thorough explanations quoll!

👍 1
👆 2
Apple 2021-06-22T16:53:35.490200Z

(= 25 ((fn [n] (* n n) 5))

dwduck 2021-06-22T16:54:03.490400Z

I would think it’s more:

(= 25 (#(% 5)   (fn [n] (* n n))))

👍 3
dwduck 2021-06-22T16:54:17.490600Z

The question is looking for a function that takes a function as an argument…

Patrick Tu 2021-06-22T16:58:04.491300Z

That's the answer, but the syntax is mind-bending. I understand # declares a function and % is a placeholder. 5 is the argument?

dpsutton 2021-06-22T17:03:02.491500Z

i've been doing clojure/script for quite some time and that is a very confusing question. and i don't really see any benefit to it

☝️ 2
Patrick Tu 2021-06-22T17:04:38.491700Z

I discovered Clojure/script last night from a job posting for a position at Roam Research

Patrick Tu 2021-06-22T17:04:57.491900Z

I love the product and thought it would be nice to learn to language they use

Carnun 2021-06-22T17:08:30.492100Z

5 is the argument passed to the function subbed in for % , namely (fn [n] (* n n)). So... yes. But it's not an argument of #(% 5) (a.k.a. (fn [f] (f 5))), just a hardcoded value.

Patrick Tu 2021-06-22T17:35:30.492300Z

Thank you guys!

👍 2
dwduck 2021-06-22T17:39:31.492700Z

The question is just trying to show you can pass a function as an argument… but it certainly is done in a confusing way. 🙂 It might have made more sense to provide the #(% %), and have the user create any function to pass in that satisfies the answer 25.

quoll 2021-06-22T18:39:58.493100Z

I know that this has been explained, but I feel like I want to explain it differently… Talking about arguments for functions may make it unclear that there are multiple levels of function call, and different arguments at each level. That’s adding complexity over the actual task, making it much less clear. Abstracting it down, it comes to: (answer (fn [n] (* n n))) Where the value of answer is what we’re looking for. This says that answer takes a single argument, and it’s the function that’s defined. When looking at the correct answer: #(% 5) I’d rather use the long form to explain, so an equivalent is: (fn [f] (f 5)) This is an anonymous function that takes another function and uses it on the number 5. We know that the answer is 25, and the function being provided is a squaring function, so that’s how we know that we want to apply to 5. The final expression is: ((fn [f] (f 5)) (fn [n] (* n n))) What a mess. What it says is: • calculate the first expression to obtain a function that takes a function and applies it to 5 • calculate the second expression to obtain a function that takes a number and squares it • calculate the result of applying the first expression (which evaluated as a function) to the second expression (which also evaluated as a function) That’s a lot for one expression. Not difficult when you’re used to it, but really tough for someone who is new to the ideas

👍 6
dwduck 2021-06-22T19:24:35.494400Z

I think your explanation adds a LOT of value, thanks! :thumbsup:

quoll 2021-06-22T21:38:01.494800Z

Thank you