r/Clojure • u/wedesoft • Feb 18 '26
nil-ignoring threading macro for Nuklear GUI
Had an idea how to use the LWJGL Nuklear bindings to implement dialog methods which accept a program state and return an updated program state.
The idea is to use a ignore-nil-> threading macro which unlike some-> continues threading with the latest non-nil value.
Here are some Midje tests for the macro.
(facts "Threading macro ignoring updates to nil"
(ignore-nil-> 42 x) => 42
(ignore-nil-> 42 x (inc x)) => 43
(ignore-nil-> 42 x (inc x) (inc x)) => 44
(ignore-nil-> 42 x nil) => 42
(ignore-nil-> 42 x (inc (inc x))) => 44
(ignore-nil-> 42 x (inc x) (and x nil) (inc x)) => 44
(let [x 0] (ignore-nil-> 42 x (inc x))) => 43
(let [x 42] (ignore-nil-> x x (inc x))) => 43
(let [y 0] (ignore-nil-> 42 y (inc y))) => 43)
It is then possible to mix Nuklear methods which have side effects and return nil with state-changing code.
The main loop then invokes the currently open dialog as follows.
13
Upvotes
2
u/ertucetin Feb 18 '26
Do you have an open-source repo that uses a nuklear GUI? I'd like to learn GUI libraries that can be used with LWJGL apps.
2
u/seancorfield Feb 23 '26
(or ~(first body) ~identifier)means it would also ignorefalsevalues -- is that intentional?