Clojure is a general-purpose language supporting interactive development that encourages a functional programming style, and simplifies multithreaded programming.
Questions tagged [clojure]
91 questions
41
votes
3 answers
What's so great about Clojure?
I've been taking a look at Clojure lately and I stumbled upon this post on Stackoverflow that indicates some projects following best practices, and overall good Clojure code. I wanted to get my head around the language after reading some basic…

marco-fiset
- 8,761
14
votes
3 answers
If you can use def to redefine variables how is that considered immutable?
Trying to learn Clojure and you can't help but be told continually how Clojure is all about immutable data. But you can easily redefine a variable by using def right? I get that Clojure developers avoid this but you could avoid changing variables in…

Evan Zamir
- 319
- 3
- 7
8
votes
1 answer
Clojure: vars, atoms, and refs (oh my)
also: defs, java fields, agents
The clojure website has documentation for these concepts:
Vars
Atoms
Refs
Agents
I understand the words, but I don't conceptually get the purpose / meaning of these. When should I / how can I know when to use them?

amara
- 1,310
- 11
- 18
6
votes
2 answers
Alternate method to dependent, nested if statements to check multiple states
Is there an easier way to process multiple true/false states than using nested if statements? I think there is, and it would be to create a sequence of states, and then use a function like when to determine if all states were true, and drop out if…

octopusgrabbus
- 699
5
votes
1 answer
Is re-defing idiomatic in clojure?
Simple example:
(def ticks 0)
(defn run-iteration []
(def ticks (inc ticks)))
Though the usual case involves things that don't change more than once every several hundred ms.
How to do this idiomatically?
Edit: and why is the idiomatic way…

amara
- 1,310
- 11
- 18
3
votes
1 answer
What is the relation between clojure reducers and loop fusion
I just stumbled upon Clojure reducers library.
It looks a lot like loop fusion. However the term is not mentioned anywhere on the page. Is there a difference between the two?

Simon Bergot
- 7,970
- 4
- 35
- 55
1
vote
1 answer
How to unit test hiccup template generating function?
How do I unit test a function that takes a list of maps and returns an HTML table with the same data in Clojure/Hiccup?

Amogh Talpallikar
- 2,035
1
vote
2 answers
Is it bad form to stage a function's steps in intermediate variables (let bindings)?
I find I tend to need intermediate variables. In Clojure that's in the form of let bindings, like cmp-result-1 and cmp-result-2 in the following function.
(defn str-cmp
"Takes two strings and compares them. Returns the string if a match; and nil…

octopusgrabbus
- 699
0
votes
1 answer
More idiomatic syntax for 2nd level vector value update
I'm pretty sure there has to be a more idiomatic way of writing this:
(defn update-2nd-level-vector
[map index value]
(assoc map :key1 (assoc (get map :key1) :key2 (-> map (get-in [:key1 :key2]) (assoc index value)))))
Example of its…

m0skit0
- 175
0
votes
2 answers
What is the exact semantic of reduce in clojure?
The Clojure docs regarding (reduce f val coll) state:
If val is supplied, returns the result of applying f to val and the
first item in coll, then applying f to that result and the 2nd item,
etc.
So I tried:
(reduce str ["s1" "s2"]…

Arne
- 153