beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Evan Haveman 2021-05-15T00:26:14.270300Z

clj -M --main cljs.main --compile foo.core --repl works fine to open a repl connected to a browser and im able to run my code but when i try clj -M --main cljs.main --repl-env node --compile foo.core --repl the repl loads (without the browser) but i can’t run my code. `Execution error (ReferenceError) at (<cljs repl>:1). foo is not defined`

NoahTheDuke 2021-05-15T01:49:14.271Z

Maybe ask in #clojurescript

Evan Haveman 2021-05-15T01:57:03.271200Z

i did at first but felt it was such a newb question i moved it here! 🙂

👍 1
Evan Haveman 2021-05-15T01:58:02.271500Z

i also wonder if the answer is “if you’re not using the browser, just use clojure”…

NoahTheDuke 2021-05-15T01:59:14.273100Z

Hah that is definitely an answer. You could write everything in cljc and use the Clojure repl, provided you don’t need any features of node (fs, event emitter etc)

Evan Haveman 2021-05-15T02:00:05.273300Z

yeah i don’t need any of that

seancorfield 2021-05-15T04:42:55.273500Z

@evanhaveman Something worth bearing in mind is that ClojureScript has to go through a compile-to-JS phase, which requires the ClojureScript compiler which is running on the JVM anyway. So if you don’t need a browser and you don’t need Node.js features, I would probably just write it as .cljc files, run it on the JVM as Clojure while you’re developing stuff, and use Olical’s cljs-test-runner to make sure it compiles and runs as ClojureScript. That’s what I do for HoneySQL (on the v2 branch).

👍 1
Evan Haveman 2021-05-15T05:48:56.273700Z

thank you - i’ll look into cljs-test-runner!

Ivan Koz 2021-05-15T06:03:46.273900Z

@jimmyssj3 Atom is implemented in such a way that JVM ensures that any successful write will be seen by any subsequent reads in other threads. Lock-free update mechanics are possible because of CAS, compare and swap. 1. Thread reads "current value" of the atom as a "last known" 2. Runs a function to produce a "new value" 3. Tries to swap "current value" by the "new value" 4. If "current value" equals to "last known" value, "new value" is written, else, another thread was faster to update the value and current thread should retry the whole process. (Hence no side-effects requirement for a "new value" function)

Ivan Koz 2021-05-15T06:08:43.274300Z

Here is an example of 100 threads doing 10k increments each to the integer stored in the atom.

(defn test-atom [nthreads niters]
  (let [ref (atom 0)
        pool  (Executors/newFixedThreadPool nthreads)
        tasks (repeat nthreads #(dotimes [_ niters]
                                  (swap! ref inc)))]
    (doto pool
      (.invokeAll tasks)
      (.shutdown)
      (.awaitTermination 60 TimeUnit/SECONDS))
    @ref))
=&gt; #'user/test-atom
(test-atom 100 10000)
=&gt; 1000000

Ivan Koz 2021-05-15T06:32:21.274500Z

You may wan't to dig deeper into JVM memory model to understand the foundation clojure is built on, but that isn't strictly necessary. https://shipilev.net/blog/2014/jmm-pragmatics/

zackteo 2021-05-15T07:28:49.279Z

Hi im trying to use simple-v-table in re-com but I keep getting this issue re_com.v_table.v_table(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null. I know I am probably missing something - where a simple h-box is different from simple-v-table but I don't know what I might be missing?

zackteo 2021-05-15T10:14:52.279900Z

okay turns out I missed out a dependency for v-table :face_palm:

teodorlu 2021-05-15T11:10:36.283500Z

Hey! I remember seeing a way to work with time in Clojure/Clojurescript that enabled using EDN reader literals (?) for serialization. So that when exporting a semantic type for time/datetime, you'd get something like

#library-provided-tag "time representation with string"

;; or

#library-provided-tag {:minutes 33 :hours 1231 :other-stuff "perhaps?"}
, which you could print to the REPL and read back in, serialize and deserialize with EDN, etc. Does this sound familiar to anyone of you? Thanks!

Todd 2021-05-15T12:01:55.287200Z

Thanks again @seancorfield and @alexmiller (as well as others) for your responses here. They have been helpful in a brief time in Clojure. Unfortunately (and fortunately), I have found an interesting position with another company doing low level, open source, system monitoring code but its primarily Java with some Kotlin and Scala among other languages. So my 2 months doing full stack Clojure has been fun and I hope to return to it again someday. Take care ya’ll and see you later.

danieroux 2021-05-15T12:41:37.287300Z

https://www.juxt.land/tick/docs/index.html#_serialization

👍 1
teodorlu 2021-05-15T13:48:58.287600Z

Nice, thanks!

grazfather 2021-05-15T15:17:10.290300Z

What’s the ‘right way’ to support a list of things that may have one or two elements, and basically if each sublist is one element, reuse the first element.

(def files [["src1" "dst1'] ["src2']])
(doseq [[src dst] files]
  (let [dst (or dst src)]
    ...

valerauko 2021-05-15T16:02:46.291800Z

What's the place for Clojure feature requests again?

dpsutton 2021-05-15T16:06:55.292100Z

http://ask.clojure.org is a good place for questions like that

sova-soars-the-sora 2021-05-15T16:19:40.292700Z

Hi, what does

2021-05-15 09:42:27.928:WARN:oejs.HttpChannel:qtp314487999-538: handleException /audiofile-here.m4a java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 200000/200000 ms
mean?

sova-soars-the-sora 2021-05-15T16:23:41.292800Z

nevermind. I found the facts: the stack trace indicates that the server was writing some content, but the TCP connection got congested, so the write http://blocked.To unblock the congestion, the client must read (and communicate that to the server via TCP ACKs). Apparently this did not happen for 30 seconds, so Jetty closed the connection due to idle timeout.

valerauko 2021-05-15T16:28:00.293Z

not really following but maybe use last ?

valerauko 2021-05-15T16:50:03.293800Z

thanks added a request, upvote if you suffer from ^"[Lridiculously.verbose.type.Hints;" too https://ask.clojure.org/index.php/10609/into-array-should-not-need-type-hints

👍 1
grazfather 2021-05-15T18:24:57.295200Z

No, basically I want if the second element is there then use it, otherwise use the first again

sundarj 2021-05-15T19:35:15.295900Z

user=&gt; (def files [["src1" "dst1"] ["src2"]])
#'user/files
user=&gt; (defn copy [src dst] (println "copying" src "to" dst))
#'user/copy
user=&gt; (doseq [[src dst] files
               :let [dst (or dst src)]]
         (copy src dst))
copying src1 to dst1
copying src2 to src2

grazfather 2021-05-15T22:57:48.296200Z

oh cool, I didn’t know about :let. Is the dst (or dst src) idiomatic?