This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (2)
- # asami (5)
- # beginners (22)
- # biff (2)
- # cider (1)
- # clara (3)
- # clojure (17)
- # clojure-europe (7)
- # clojurescript (29)
- # core-async (2)
- # datahike (1)
- # fulcro (11)
- # gratitude (2)
- # integrant (2)
- # lsp (6)
- # music (2)
- # observability (1)
- # off-topic (36)
- # polylith (4)
- # quil (2)
- # reagent (15)
- # tools-deps (36)
- # xtdb (16)
Having a real fun time with into vs merge gotchas :)
I am looking for information regarding data driven boolean expressions. For instance the following expression could be written several ways
(if (and (> a b) (< c d) (> d e) (> a d)) -1 default)
Or we could notice that swapping the ordering yields 1 function
(cond (> a b) -1 (< c d) -1 (> d e) -1 (> a d) -1 :else default)
Or if you're trying to be clever
(if (every? (partial apply >) [[a b] [d c] [d e] [a d]])) -1 default)
Are there more idiomatic ways to apply functions to data? Or to represent your flow control using data? Or is using data to drive control flow not encouraged favoring more literal expressions? Also are there any simple, idiomatic ways to convert a boolean to its integer equivalent (i.e. 1 for true, 0 for false)?
(if (every? true? (map > [a d d a] [b c e d])) -1 default)
Is there an equivalent to
repeatedly which takes an initial arg, and passes previous results to the same function?
(repeatedly 5 #(+ 2 %) 0)
which would yield
(0 2 4 6 8)
Ah, I made a mistake, it would yield 8 only
so I guess I could call last on that
but if its a sufficiently large list, that'd be poor performance, no?
If your computation for an item is dependent on previous calculations, you don't have much of a choice.
it is only dependent up on the immediately previous calculation
there are lots of primitives that would work for this. you could do something like
(letfn [(go [f x n] (if (pos? n) (recur f (f x) (dec n)) x))] (go #(+ % 2) 0 1000))
I suppose I could write a recur wrapper which simply returns the final value when
n is reached
oh what is go?
Ah, should have seen that before asking... I do see a
go in clojure.core
oh, are the .'s not nested?