can spec conform be used at runtime (not for tests)?
(reduce #(if (mod %2 7) (reduced %2) %1) (iterate inc 20))
@kbosompem A reduce version
reduced
is basically a way to insert a break statement.
Yes. And I'm pretty sure tests are evaluated at runtime too, unless you're doing something strange 😉
strange is subjective
but I guess I meant to say "in production"
it's cljs, not clj
Should be fine
the loop/recur version is more readable IMO
@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 sameHow do I connect to a repl into a docker?
Forward the NREPL port with -p?
Specifically I want to write functions to hit apis on a client that unfortunately is running in a docker
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?
Yeap I believe so :thinking_face:
@teodorlu how do I do the forwarding of NREPL port?
docker run -p 3306:3306 your-thing
should forward port 3306 in your system to port 3306 inside your container.
I think you can control the port NREPL uses with a .nrepl-port
file.
@zackteo did you figure it out?
@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)
Sounds hard.
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 ...
Though I'm speculating now, and other people might have better advice.
Why bother with "direct docker"? Then you get direct container access, and don't have to bother with port mapping.
Okay let me think about that 🙂 Will be heading to sleep first but will think through it tmr. Thanks for your help 😄
@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
If I've understood the problem right, we're probably stuck with what Jepsen provides.
oh - I missed that aspect
Which seems more idiomatic?
(or (some-> …
(f))
<alternative>)
(if-let [x …]
(f x)
<alternative>)
First one is code golf IMO