This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-14
Channels
It's virtual a no-op for some data structures: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L531
seq
on a LazySeq
is a bit more complex as it has to realize enough to get something seqable: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java#L50
RT.seq()
delegates other cases to seqFrom()
which is just below it and deals with the other types.
A seq gives you a logical list view on a data structure, whether that's lazy depends on the object
I am using mount
to manage my app state (more specifically, just the database connection). There are 3 namespaces which require and reference the piece of state defined through mount/defstate
, and one of the namespaces has a main function.
How can I make sure the state is always started: 1) before the main function is called, and also 2) for REPL driven development, whenever I load one of the other namespaces in the REPL?
Currently I've acheived 1) by calling mount/start
right in -main
, but I don't know how to achieve 2). I mostly end up evaluating the mount/start myself, and it's annoying to have to do this every REPL restart
for 2, you can add a dev time path with user.clj and require the namespaces there. you will often see this file at dev/user.clj
. i might still keep the manual call to mount so your're in control, but if you want to have it happen automatically, you can also just add the (mount/start)
call there
I just want the db state to behave as a global variable that only gets set once, whenever any namespace referencing it gets evaluated, so I am open to switching to another state management library if it sounds more fitted to my usecase
Hey guys i'm back again in clojure land after a while doing other language stuff. Just wanted to know if leiningen is still a thing or should i do the deps edn stuff or even boot? I'm currently lost what to use.
Leiningen is still a very powerful tool with a lot of plugins for every need. But because Clojure cli is getting traction it is worth learning it too. You will find some things much more easy to maintain and debug. Personally i stopped using leiningen for my new projects about a year ago in favor of Clojure cli
Also i would recommend looking at the annual Clojure survey for the past few years to see current trends
Ok great regarding clojure cli i was also seeing that it gains traction currently. So i'll try my best with clojure cli.
The Clojure code will be the same regardless of the build too used. If you are used to Leiningen, then stick with it until you get back into Clojure. Leiningen is still used by a large number of projects, especially those that have existed for a year or more. Boot seems extremely niche now. Clojure CLI is growing in adoption and evolving new features, such as the recent tools.build. There can be more to learn with Clojure CLI than Leiningen, although it does bring a greater flexibility in tooling. Adding a deps.edn file to existing Leiningen projects is a relatively simple way to start adoption of Clojure CLI https://practical.li/clojure/clojure-cli/ covers example of using Clojure CLI, along with many community tools.
Hi! I have a function that has to return BigDecimal. At the end I call bigdec. Is there a better way of doing it?
Is there a better alternative to the following?
(def ^:dynamic *testing?* false)
;; a function called in multiple other functions
(defn make-response [data]
(let [eids (calculate-eids data)]
(if *testing?*
eids
(pull-from-db eids))))
;; used in comments and tests
(binding [*testing?* true]
(make-response some-data))
You could use with-redefs (with the caveat of being wary around multi-threaded tests):
(with-redefs [pull-from-db identity]
(make-response data))
Yes, pass the db as an argument and don't pull your hair our over dynamic bindings

Then in testing pass a different implementation for the db To manage this use a library like component and a configuration library like aero
I've been delaying looking into these kinds of libraries since things are still relatively simple to manage. Will keep in mind, thanks!
When you reach 2-3 logical components that need different implementations it's time, imo
It's worth being critical of what you're testing. Does your app need specific data to work? Could you abstract that into a spec? Is it that you need to be sure of a schema? Could you move that closer to where the data is used and avoid possible mistranslations?
All good questions 🙂 I've dabbled with spec, but I'm yet seriously start thinking about schemas and testing. I've definitely felt the desire for spec/malli type of thing.
Seems to fail as you'd expect on the repl, just the usual note that assertions can be turned off
user=> (swap! (atom nil) #(assert (some? %)))
Execution error (AssertionError) at user/eval3$fn (REPL:1).
Assert failed: (some? p1__2#)
if you read the (doc atom)
docstring you can see a mechanism is built in to atoms that might serve your needs