Fork me on GitHub
#beginners
<
2021-04-06
>
Aron07:04:45

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

simongray10:04:30

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

Aron10:04:46

strange is subjective

Aron11:04:14

but I guess I meant to say "in production"

Aron11:04:18

it's cljs, not clj

simongray11:04:33

Should be fine

simongray07:04:52

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

👍 3
simongray07:04:12

reduced is basically a way to insert a break statement.

🙏 3
chrisblom12:04:48

the loop/recur version is more readable IMO

pavlosmelissinos12:04:29

@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

🎉 6
👍 3
zackteo12:04:05

How do I connect to a repl into a docker?

teodorlu12:04:31

Forward the NREPL port with -p?

zackteo12:04:46

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

teodorlu12:04:30

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?

zackteo12:04:26

Yeap I believe so :thinking_face:

zackteo12:04:37

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

teodorlu12:04:08

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

teodorlu12:04:28

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

teodorlu14:04:18

@zackteo did you figure it out?

zackteo14:04:02

@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)

teodorlu14:04:34

Sounds hard.

teodorlu14:04:08

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 & in the background inside your container, then lein repl :connect ...

teodorlu14:04:38

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

teodorlu14:04:40

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

zackteo14:04:02

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

👍 3
noisesmith16:04:52

@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

teodorlu16:04:19

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

noisesmith16:04:04

oh - I missed that aspect

zane20:04:19

Which seems more idiomatic?

(or (some-> … 
            (f)) 
    <alternative>) 
(if-let [x …]
  (f x)
  <alternative>)

2️⃣ 36
simongray20:04:41

First one is code golf IMO