17,775 questions
7
votes
3
answers
4k
views
Checking for NaN in clojure
I have some algorithm which for one reason or another spits out NaNs, I would both like to just filter out these bad results for the time being, and some point later go and find out the problem. ...
15
votes
3
answers
707
views
Layout algorithm that understands compass rose
I want to visualize a graph that represents some geographical map. As such, the edges of my graph are associated with the compass rose (north, south, east, west). The graph itself is directed and can ...
0
votes
0
answers
54
views
Clojure, Missionary. Can't sample continous flows more than once
I'm following this tutorial. In the chapter on continuous flows, the author whats to demonstrate that they can be sampled at any time and they are always ready. He presents this code:
(def discrete-...
2
votes
2
answers
357
views
"rerootable" purely functional tree data structure
I recently purchased Inferring Phylogenies by Joseph Felsenstein, which is a great book about mathematical and computational methods for inferring phylogenetic trees, and have been playing around with ...
0
votes
1
answer
317
views
Interpreting a VisualVM backtrace
I'm doing CPU profiling on my Mandelbrot Set explorer. For some reason, clojure.lang.PersistentHashMap$BitmapIndexedNode.find is using a fairly large percentage of the total CPU time. When I take a ...
0
votes
1
answer
402
views
How to replace specific characters in a string in Clojure?
I'm trying to replace all single quotation marks with double quotation marks in Clojure. i.e. if the string id " 'name' " I want it to become " "name" ". How can I do ...
Advice
0
votes
3
replies
66
views
Clojure inline print for debugging
In clojure, the println function returns a nil:
\>(println "a"
a
nil
This makes it awkward to use print to access an intermediate value when print debugging:
Say I have:
(* (+ 5 10) (- ...
8
votes
1
answer
760
views
How to convert Java 17 record to Clojure map?
There is a standard function clojure.core/bean converting POJO to map:
class MyPojo{
public String getFirst(){ return "abc"; }
public int getSecond(){ return 15; }
}
IFn bean = Clojure....
Best practices
3
votes
3
replies
113
views
Event should update data structures
Consider this function:
(defn check-collision
[game]
(let [ball (:ball game)]
(let [result (collision/ball-collision? ball (:paddle game))]
(when (:collision? result)
(resolve-...
1
vote
1
answer
49
views
Parse nested metadata
One thing I like about metadata is that I can organise functions across namespaces. E.g.:
(defn ^{:category 1} a-function []
(do-stuff))
(->> (ns-interns 'this.namespace)
vals
(map ...
3
votes
1
answer
377
views
Representing just 'year' and 'year-month' in Clojure/Java
I am trying to represent time information that has precision at the scale of year or year-month. Eg. 'patient has a history of fracture of the right wrist in 1998'; 'history of headaches since October ...
1
vote
1
answer
94
views
Cannot invoke "java.lang.Character.charValue()" because "x" is null
This is the code fragment of the error:
(defn end-render
[fb]
(let [width (get-in fb [:dimen :width])
height (get-in fb [:dimen :height])
msfbo (:msfbo fb)
fbo (:fbo fb)]
...
1
vote
1
answer
99
views
How to type hint a float array?
This code
(GL33/glUniform2fv ^int (location shader "offsets") ^float [] offsets)
produces this error:
No matching method glUniform2fv found taking 3 args for class org.lwjgl.opengl.GL33
I'...
3
votes
0
answers
140
views
Fast lazy sort & deduplication over multiple sorted lazy sequences in Clojure
I implemented a few lazy sort & merge functions that are used heavily in my ReBAC authorization library, EACL, to lazily "merge" & deduplicate ~1M datoms emitted from Datomic's d/...
3
votes
1
answer
154
views
How to write an accumulative recursive function in J without looping
At the risk of asking a question with an obvious solution: if I have a function in J that takes two arguments and returns two arguments and I want to accumulate the answer's second argument and to use ...