beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Aron 2021-04-06T07:05:45.166600Z

can spec conform be used at runtime (not for tests)?

simongray 2021-04-06T07:15:52.166900Z

(reduce #(if (mod %2 7) (reduced %2) %1) (iterate inc 20))

👍 1
simongray 2021-04-06T07:16:11.167300Z

@kbosompem A reduce version

simongray 2021-04-06T07:21:12.168500Z

reduced is basically a way to insert a break statement.

🙏 1
simongray 2021-04-06T10:19:30.168600Z

Yes. And I'm pretty sure tests are evaluated at runtime too, unless you're doing something strange 😉

Aron 2021-04-06T10:55:46.168800Z

strange is subjective

Aron 2021-04-06T11:01:14.169Z

but I guess I meant to say "in production"

Aron 2021-04-06T11:03:18.169200Z

it's cljs, not clj

simongray 2021-04-06T11:26:33.169600Z

Should be fine

simongray 2021-04-06T11:27:53.169800Z

https://cljs.github.io/api/cljs.spec.alpha/#conform

2021-04-06T12:03:48.171400Z

the loop/recur version is more readable IMO

pavlosmelissinos 2021-04-06T12:33:29.179800Z

@kbosompem You're trying to do two separate things that imo don't belong together: 1. compute the list of numbers that are >=20 and divisible by 7 2. print the first of those The first one doesn't have any side-effects, the second one does (in the strict sense) Your example is a toy problem, so you wouldn't see any tangible benefits but in general I'd try to keep those apart, e.g.:

(defn gen [min q]
  (->> (range)
       (drop min)
       (filter #(zero? (mod % q)))))

(print (first (gen 20 7)))   
Of course that's not always possible or practical edit: and obviously it's not 100% equivalent to the javascript code (it doesn't start from 20) but the result should be the same

👍 1
🎉 2
zackteo 2021-04-06T12:38:05.180600Z

How do I connect to a repl into a docker?

teodorlu 2021-04-06T12:39:31.182Z

Forward the NREPL port with -p?

zackteo 2021-04-06T12:39:46.182300Z

Specifically I want to write functions to hit apis on a client that unfortunately is running in a docker

teodorlu 2021-04-06T12:42:30.182400Z

Do you want to connect an NREPL client from outside of Docker to an NREPL server running inside Docker? Or you you want to hit HTTP endpoints?

zackteo 2021-04-06T12:43:26.183Z

Yeap I believe so :thinking_face:

zackteo 2021-04-06T12:52:37.183400Z

@teodorlu how do I do the forwarding of NREPL port?

teodorlu 2021-04-06T12:54:08.184100Z

docker run -p 3306:3306 your-thing should forward port 3306 in your system to port 3306 inside your container.

teodorlu 2021-04-06T12:54:28.184600Z

I think you can control the port NREPL uses with a .nrepl-port file.

teodorlu 2021-04-06T14:05:18.186400Z

@zackteo did you figure it out?

zackteo 2021-04-06T14:29:02.189Z

@teodorlu nope not really - or rather am trying to figure out other things >< If you are wondering, am trying to use jepsen to test my distributed systems project, and not too sure how to make modifications for it. And connecting a repl is another step I need make sure my http calls are correct. (can't run the server locally)

teodorlu 2021-04-06T14:30:34.189300Z

Sounds hard.

teodorlu 2021-04-06T14:33:08.191200Z

Another option is to go into the Docker container directly. If your container ships with leiningen, you could docker run ... --entrypoint /bin/bash , run something ./jepsen? --stuff &amp; in the background inside your container, then lein repl :connect ...

teodorlu 2021-04-06T14:33:38.191900Z

Though I'm speculating now, and other people might have better advice.

teodorlu 2021-04-06T14:34:40.192800Z

Why bother with "direct docker"? Then you get direct container access, and don't have to bother with port mapping.

zackteo 2021-04-06T14:36:02.193700Z

Okay let me think about that 🙂 Will be heading to sleep first but will think through it tmr. Thanks for your help 😄

👍 1
2021-04-06T16:07:52.195400Z

@teodorlu I'd advocate for using lein to biuld a jar, but not running it inside your container, which means that in order to run NREPL one would be bundling the nrepl jar, and then providing a port as a starting argument

teodorlu 2021-04-06T16:09:19.195500Z

If I've understood the problem right, we're probably stuck with what Jepsen provides.

2021-04-06T16:15:04.195700Z

oh - I missed that aspect

zane 2021-04-06T20:15:19.204600Z

Which seems more idiomatic?

(or (some-&gt; … 
            (f)) 
    &lt;alternative&gt;) 
(if-let [x …]
  (f x)
  &lt;alternative&gt;)

2️⃣ 12
simongray 2021-04-06T20:41:41.205Z

First one is code golf IMO