This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-02
Channels
- # announcements (5)
- # beginners (35)
- # calva (15)
- # chlorine-clover (9)
- # clj-kondo (8)
- # clojure (34)
- # clojure-europe (6)
- # clojure-uk (1)
- # clojurescript (4)
- # conjure (23)
- # data-science (2)
- # datalog (6)
- # emacs (1)
- # events (8)
- # figwheel-main (3)
- # fulcro (10)
- # jackdaw (3)
- # joker (1)
- # kaocha (1)
- # malli (4)
- # nrepl (1)
- # off-topic (1)
- # pathom (1)
- # re-frame (4)
- # reagent (2)
- # reveal (11)
- # rewrite-clj (15)
- # rum (1)
- # sci (61)
- # shadow-cljs (1)
Hi, good day everyone! I’m trying to get my feet wet with Clojure internals. Currently I’m reading iterate
implementation in src/jvm/clojure/lang/Iterate.java
and it caught my attention that _seed
and _next
are volatile variables. I’ve also seen that in first implementation seed
was just final
and got changed to volatile
. Could someone explain a bit, or show me a path to understand why is that? Why it’s important for _seed
and _next
to have always the same value visible in all threads? What would happen if that wasn’t the case? Is that anyhow connected with laziness?
👋 ! Did you check https://github.com/clojure/clojure/commits/master/src/jvm/clojure/lang/Iterate.java ? That should answer the first question (specifically, see how commits are linked to JIRA tickets)
> Why it’s important for seed and next to have always the same value visible in all threads?
I think this question answers itself... :) imagine if this wasn't the case and that (take 10 an-iterate-object)
returned different results depending on the thread you're on. That would seem very broken
hi! thanks for response 🙂 I checked commits, yes 🙂 I’m just starting to understand multithreading and I lack proper mental models, so it’s hard for me to imagine particular situation and particular error that could happen because those variables were not volatile
Sure :)
recommends the JCIP book, I can second that; with it the 'why' for volatile
etc will come more naturally
Writes to non volatile fields are not guaranteed to be seen by other threads
any vscode / calva users? How do I stop a command in the repl? lol.. it's just looping
There is a #calva channel if you don’t get an answer here
next.jdbc question - where can i specify the builder-fn in here? Want to get lowercase qualified keys
(with-open [conn (jdbc/get-connection config/h2-spec)]
(sql/query conn ["select * from connections"]))
Got it myself
(with-open [conn (jdbc/get-connection config/h2-spec)]
(sql/query conn ["select * from connections"] {:builder-fn rs/as-lower-maps}))
Hi, is there some kind of "in memory" file / buffer that can act as a file? Basically want to test reading files, but I don't want to actually create any on the filesystem.
is using files part of the end user contract?
if not, I strongly disrecommend using files explicitly, and instead build things to use inpustream / outputstream
Even if files are part of the end user experience, it's much easier to use i/o streams internally, and make the fact that it's a file a runtime implementation detail. The JVM already guarantees you can do the same things with file streams you can do with other streams, that doesn't need special test coverage.
it is for the enduser. And I've split my code in two parts. One that reads the file, the other that does the processing. And I can do most of my testing on the second part, but I still want to write a few tests for the first
Oh looks like this works
(let [a (
Hi, I have a set of tests (using clojure.test), all in one namespace that have an each fixture declared. Now I want to run the same set of tests unchanged (same input / output and assertions) twice, where the only difference is that in the each function, a different file is loaded for the second run. I guess there is a way to do that, but cannot come up with one right now that is simple, so, I'd be interested in ideas in how to solve that. It would also be great to see, if a test fails, with which precondition it failed.
@sveri About the only place where I use dynamic vars is with clojure.test-related code. Might also work in this case.
Would it bea idiomatic to run the test function twice? Something like:
(defn database-setup [f]
(create-test-specs)
(f)
(create-test-specs-without-paths)
(f))
-.- I am using kaocha, which has an open issue for support of test-ns-hook
https://github.com/lambdaisland/kaocha/issues/29 So unless I change my test runner I will have to look for a different solution.
Hi everyone.
As an experienced Clojurist, how often do you use https://twitter.com/hashtag/Clojure?src=hashtag_click's (comment )
form in your day to day development?
Do you have any other use case for it other than trying out something during development?
Do you later delete it or do you push it along to production?
I use it every day as a place to evaluate code into my repl. I often leave the blocks in committed code for the next time I'm working there
@hadilsabbagh18 We use it at work to build all our deployment artifacts. And I maintain it.
@kraulain I use (comment ..)
every day. I leave a lot of the comment blocks in the code when it is committed. I use it both to explore the problem space and the solution space, as well as to provide "set up" code for use with the REPL. You'll see that sort of thing in several of my open source projects too, for example https://github.com/seancorfield/usermanager-example/blob/master/src/usermanager/main.clj#L212-L219
Another, longer example is in next.jdbc
: https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc/connection.clj#L283
I also generally have a (comment ...)
block at the bottom of my files. It's often my scratchpad for building up functions and implementations. Sometimes I migrate them into tests.
https://gitlab.com/jamesleonis/dht-cljc/-/blob/master/src/dht_cljc/infohash.cljc#L58