This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-24
Channels
- # announcements (6)
- # beginners (89)
- # calva (75)
- # cider (37)
- # clj-kondo (1)
- # cljs-dev (19)
- # cljsjs (8)
- # clojars (1)
- # clojure (122)
- # clojure-europe (6)
- # clojure-italy (41)
- # clojure-nl (18)
- # clojure-uk (24)
- # clojurescript (26)
- # cursive (6)
- # data-science (5)
- # datomic (51)
- # emacs (28)
- # fulcro (8)
- # graalvm (13)
- # hoplon (1)
- # immutant (1)
- # jobs (3)
- # joker (1)
- # keechma (43)
- # lambdaisland (1)
- # leiningen (37)
- # midje (1)
- # nrepl (2)
- # off-topic (32)
- # re-frame (3)
- # reagent (24)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (33)
- # sql (7)
- # tools-deps (11)
because the return value is always nil
If you want something that always returns nil
with no side effects, you can just use nil
instead.
Sorry but I still didn’t get the point. Return always nil means a function is side effect?
No matter what dotimes
expression you write, that entire dotimes
expression will always return the value nil
.
It will never ever return any other value.
dotimes
will evaluate its body the given number of times, and throw away all of their return values.
then return nil
.
So if you want to get back return values of the body of something that is executed repeatedly, you should not use dotimes
If you execute (dotimes [i 10000] (+ i 5))
you will get back nil, use up some electricity, and convert it to heat.
If you want something that always returns `nil` with no side effects, you can just use `nil` instead.
please can you give an example. I didn`t get this.Suppose you want a function that returns true
if x is greater than 5, otherwise it returns nil
.
I could write it this way: (defn x-gt-5 [x] (if (> x 5) true (dotimes [i 10000] (+ i 5))))
or I could write it this way: (defn x-gt-5 [x] (if (> x 5) true nil))
The first way is not such a good idea.
Hi, how do you set environment variables in clojurescript ? I’ve been using https://github.com/yogthos/config for the back-end, but doesn’t seem to be supported in clojurescript ?
I assume, you’re on nodejs?!
I personally use https://github.com/weavejester/environ for Clojure, but it should support ClojureScript as well
I'm wondering, given a (edn) map, is idomatic, if you need to get to a sub value, to do this (-> my-map :rootkey :subkey1 :subkey2)
I know there is (get-in my-map [:rootkey :subkey1 :subkey2])
, but is it just a matter of preference?
minor nitpick: edn is a string format, what you have is an instance of clojjure.lang.IPersistentMap, or you can just call it a hash-map
in fact java.util.Map even works here (a clojure map is both)
i've seen both usually for extracting i use get-in
but for transformation i use ->
I use get-in more now days. Can be chained in with -> like (-> s some-func (get-in [:path :to]) some-other-func)
btw. the "keyword-based approach" also allows you to specify a default value:
(:b {:a 1} :not-found)
;;=> :not-found
@dharrigan I also use get-in
. For transformation I think -> or --> macros are better
Question is doseq an antipattern? Should be preferable to use map and then run! For evaluating the lazy coll?
It's an antipattern to misuse doseq, but there are legitimate uses.
@darioszr run! is a replacement for map, I use run! when it's more straightforward to describe the operation as a function of one argument, and doseq when it's more straightforward to describe it as a body of operations
(run! g (map f x)) can always be replaced by (run! (comp g f) x)
doseq is eager. It always returns nil. Because it always returns nil, it is useless for returning a sequence of processed items. dotimes shares these properties with doseq.
oh yeah, the "for evaluating the lazy coll" part is weird there
That is why the doc strings for both doseq and dotimes say that their bodies are "presumably for side effects", because if they did not have side effects, you should very likely be using something other than doseq or dotimes.
OK thx ! I'm iterating over a list of maps apply a function with the coll , then it can be that this collection contains also another collection so I needed to do map in map kind-of 😁
are you doing this in order to construct a resulting data object, or purely for side effects?
If you like the way that doseq helps you iterate over nested things, but you want to return a value, for
might be helpful.
But it is certainly possible to do a map
, where the function you provide to it does a map
on the elements of the sequence traversed by the outer map
.
Uh, I said that last sentence incorrectly, I think..
I meant: It is certainly possible to do a map
, and give it a function that also uses map
. The latter map
can straightforwardly be used to traverse over sequences or collections that are elements of the "top level" sequence or collection.

OK thx ! I might check and rewrite it without doseq. I'm basically dispatching depending on the value of some conf, and then from there I call a Client API call for getting the result
ding ding -- you are doing a side-effect, and this cool and a totally appropriate use of doseq

https://stackoverflow.com/questions/31899630/the-meaning-of-side-effect-in-clojure#31899851 just as reminder to myself
In case of curiosity, I have seen some Talks about S3 advantages as storage solutions for a clojure application. But I was looking for an opensource solution for it, which one did you tried(a list is also welcome:clj: ) ? mean I would like to build an opensource project for learning, where justr try different storage solution à la s3
@darioszr We're using the Cognitect AWS library for our S3 stuff.
My rationale behind this, is that I got insipired by Rich talk about plop programming (place oriented programming) and since I don't want use S3, I was wondering to use some alternatives.(even if I need maybe to setup it first etc) I have found riak out there, which I was considering for building an app on top of it
Is there a good way to get clojure.jdbc
to return java.time.OffsetTime
for timezonetz
columns in Postgres?
@atamiser Do you mean clojure.java.jdbc
or clojure.jdbc
?
If you mean clojure.java.jdbc
, the docs talk about how to do that here http://clojure-doc.org/articles/ecosystem/java_jdbc/using_sql.html#protocol-extensions-for-transforming-values
(you'll need to extend IResultSetReadColumn
to whatever PostgreSQL-specific type that column is in JVM-land)
I fear my problem is more subtle than that. By default, the Postgres JDBC driver returns java.sql.Timestamp
values for timezonetz
, which destroys the timezone information contained in the field, so by the time the value reaches IResultSetReadColumn
, it has already lost its timeone information. The Postgres JDBC driver can deserialize timezonetz
fields to better Java time objects, but only if you specifically request the right class in the ResultSet.getObject
call, but I don't currently see an easy way to do that with clojure.java.jdbc
If you meant TIMESTAMPZ
then this doesn't store timestamp either - and in the same way as TIMESTAMP
is stored as UTC internally.
quick question about multimethods: can multimethods do multiple parameter? like (defn x ([y] (x y nil)) ([y z] (do-stuff y z)))
? if not, is there a common idiom for doing so?
the documentation makes it seem like there isn't, but clojuredocs doesn't have any examples showing yes or no, lol
ser=> (doc defmethod)
-------------------------
clojure.core/defmethod
([multifn dispatch-val & fn-tail])
Macro
Creates and installs a new method of multimethod associated with dispatch-value.
nil
user=>
oh, interesting, okay
You're right, it doesn't destroy the TZ info. I'm getting confused by a clojure library I'm using to handle Java 8 times.
I'm having trouble making that work in the repl, @hiredman. if you don't mind looking this over, can you tell me what i've done wrong?
user=> (defrecord Step [c])
user.Step
user=> (def step (->Step 5))
#'user/step
user=> (defmulti continue (fn [x] (class x)))
#'user/continue
user=> (defmethod continue user.Step
#_=> ([x] (continue x nil))
#_=> ([x y] (println "you gave me y: " y)))
#object[clojure.lang.MultiFn 0x47b269c4 "clojure.lang.MultiFn@47b269c4"]
user=> (continue step)
Execution error (ArityException) at user/eval5886$fn (form-init3452919453452640532.clj:2).
Wrong number of args (2) passed to: user/eval5880/fn--5881
ah, that's what I was missing
thank you!