Fork me on GitHub
#beginners
<
2023-01-15
>
jdavredbeard14:01:06

I found this snippet in a library - is the doc string accurate here? It looks like this eager-or uses normal or under the hood, which is not eager, so is this actually eager?

(defn eager-or
  "A version of `or` that always evaluates all its arguments first"
  ([] nil)
  ([x] x)
  ([x y] (or x y))
  ([x y z] (or x y z))
  ([x y z & rest]
   (reduce #(or %1 %2) (or x y z) rest)))

moe14:01:13

The docstring is false

moe14:01:10

oh, wait, no, i got that completely wrong

moe14:01:29

by accepting the values as function arguments it is causing them to be evaluated

👀 2
jdavredbeard14:01:33

maybe the [x y z & rest] case should use eager-or too then

jdavredbeard14:01:51

or no, its using an anon function which would also evaluate arguments eh

moe14:01:17

sorry about the bad call, running on fumes over here

jdavredbeard14:01:56

to err is human, to correct oneself divine

❤️ 6
ghadi14:01:10

why would one want eager or?

moe14:01:05

beats me

jdavredbeard15:01:28

so I confess I am trying to understand myself, but I feel confident that the author of this library knows more than I do, which is which I am studying it... in this library looks like its used to sort of propagate events to child components

jdavredbeard15:01:38

so not so much as a way to make a choice

moe15:01:59

oh yeah i was just looking at that today

jdavredbeard15:01:58

its cool stuff! there isnt a built in dropdown component yet so I've been trying to make my own frankenstein version with the available code

moe15:01:53

i'm working on a wavetable synthesizer (as of today) and was figuring out what frontend i wanted it to have

jdavredbeard15:01:49

oh awesome... yeah I started playing with humble bc I wanted to avoid JS... let me know if find something you like better!

skylize16:01:38

I took a glance at some of the code using this function and concluded it would be easier to grock if they just used let with or.

(let [case1 (foo)
      case2 (bar)]
  (or case1 case2))
That clearly separates the branching-return logic from the declaration that everything must be calculated; and avoids requiring a custom control-flow function with somewhat surprising behavior.

2
jdavredbeard18:01:33

@U04HK53G7SQ what are you using to generate sounds?

moe18:01:03

I'm not there yet, I'm writing the DSP functions with core.matrix at the moment

moe18:01:35

Then I'll do visualisation, then synthesis

moe18:01:09

apart from the fft stuff, which could easily be rewritten, it's all platform-agnostic. i'm still torn about whether to have it be a react app or not

moe18:01:26

because i'll need all kinds of widgets

zackteo17:01:03

Hello, I was struggling with java interop in Clojure. I wanted to convert this java example from https://github.com/chocoteam/choco-solver (Overview) I just managed to figure it out. But I would like to ask, how am I suppose to sensibly know that I should use things like into-array to convert the type etc. Are there any good, extensive and recommended java interop resources I should study to gain a better grasp of this? (Especially for someone like myself who has not ventured deeply into Java before; and instead started with Clojure right off the bat)

zackteo17:01:14

My uncleaned code atm:

(def model (Model. "my first problem")) 

(def ^IntVar x (-> model
                   (.intVar "X" 0 5)))
 

(def ^IntVar y (-> model
                   (.intVar "Y" 0 5))) 
 
;; (.post (.element model x (int-array [5 0 4 1 3 2]) y))
 
(.post (.lt (.add x y) 5)) 

(-> model
    .getSolver
    (.setSearch (into-array
                 ^"[Lorg.chocosolver.solver.search.strategy.strategy.AbstractStrategy"
                 [(Search/inputOrderLBSearch (into-array
                                              ^"[Lorg.chocosolver.solver.variables.IntVar;"
                                              [x y]))])))
 
(.solve (.getSolver model))

(.printStatistics (.getSolver model))

moe18:01:00

I don't know about your broader question, but you can just (into-array AbstractStrategy [...]) and (into-array IntVar [x y])

moe18:01:01

it looks like you're trying to type-hint the vector as a primitive array, using a string, which isn't going to do anything

didibus21:01:34

Have you read.the official doc?

simongray09:01:27

varargs is a particularly gnarly area of interop, unfortunately. I hope it is fixed in a coming version of Clojure.

zackteo09:01:25

Yeap the official docs doesn't really help me whenever I'm stuck with stuff like this

rolt10:01:58

related: https://clojure.atlassian.net/browse/CLJ-2631 I used the typed-array macro proposed when I encountered this issue edit: I misread, I though you had reflection issues. But I'll leave the comment because you may encounter some soon 😉

👍 2
zackteo12:01:48

I thought I did encounter reflection issues but maybe Moe is right and what I thought was type hinting is doing nothing