This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-09
Channels
- # asami (1)
- # babashka (4)
- # calva (22)
- # clerk (2)
- # clj-kondo (32)
- # cljdoc (2)
- # clojure (49)
- # clojure-europe (9)
- # clojure-norway (3)
- # clojurescript (4)
- # data-science (5)
- # datascript (8)
- # datomic (7)
- # events (1)
- # fulcro (3)
- # hyperfiddle (62)
- # malli (4)
- # missionary (3)
- # off-topic (41)
- # polylith (11)
- # re-frame (19)
- # remote-jobs (2)
- # sci (7)
- # sql (51)
- # tools-build (2)
- # yamlscript (38)
When running nREPL in a deps-driven project, is it possible to specify a port with an env var? something like:
NREPL_PORT=9911 clj -M:local/nrepl:foo:bar
I've done that many times with lein, but got stuck with deps:local/nrep
is my global ~/.config/deps.edn profile:
:local/nrepl
{:extra-deps
{nrepl/nrepl {:mvn/version "0.9.0"}
cider/cider-nrepl {:mvn/version "0.32.0-alpha1"}}
:main-opts ["-m" "nrepl.cmdline"
"-i"
"--middleware" "[cider.nrepl/cider-middleware]"]}}
I had a typo in the origin message, now it's fixed. The question is, how to pass a port with an env var?
Just in case - it's possible to do so via a CLI arg.
But there doesn't seem to be a buit-in way to use an env var. However, it's just a few lines to replace nrepl.cmdline
with your own namespace that wraps the original and extracts the port from the env.
clj -M:local/nrepl:foo:bar --port 7777
will start the REPL on the given port, so
clj -M:local/nrepl:foo:bar --port $REPL_PORT` will pick up the value from the associated environment variable and pass it in to the main-opts
Same can be done for -X using
:port $REPL_PORT
for clojure.exec
You may have luck with a .nrepl.edn file as well https://nrepl.org/nrepl/usage/server.html
Arguments on the command line are added (or replace) options defined in the alias.
If always using the same port (or using it quite often), then the --port
can be added to the alias and overridden on the command line when required.
:local/nrepl
{:extra-deps
{nrepl/nrepl {:mvn/version "0.9.0"}
cider/cider-nrepl {:mvn/version "0.32.0-alpha1"}}
:main-opts ["--main" "nrepl.cmdline"
"--interactive"
"--port" 7777
"--middleware" "[cider.nrepl/cider-middleware]"]}}
Then call clj -M:local/nrepl:foo:bar --port $REPL_PORT
if a port other than the default is requiredrelated question: I'm trying to specify --host but it looks like it makes no effect. the host is always localhost. What do I do wrong?
I want nREPL be available for other machines, so I specify "--host" "0.0.0.0"
but the console renders
Even though it prints localhost
, have you tried checking what open ports you have? Or just accessing that nREPL server via your external host.
Speculating here, but I suspect that some underlying code might simply be reverse-resolving 0.0.0.0
as localhost
and printing that.
To share the nrepl port with other machines on the local network I assume the IP address of the machine running the repl should be used, e.g 192.168.0.10
What doe ipconfig or if config or look in /etc/hosts if on Linux/unix
0.0.0.0
should also be working for listening since it means "every available interface". If it doesn't work, there's probably a bug.
no I've tried 169.254.117.51
but it didn't work, and I still see localhost:9911 in the console
Just tried, made sure it's not firewall.
Sever/client using 0.0.0.0
- worked (but due to a bug - the server is actually listening on 127.0.0.1
).
Server on 0.0.0.0
with client on a particular non-localhost interface - connection refused (a bug, the server is also listening on 127.0.0.1
).
Server/client on non-localhost - connection refused (also a bug).
Yeah, after a brief look at the code, seems like --host
is ignored and replaced with --bind
at some point.
Specifying host in a .nrepl.edn
file in root of project seems to work, reports the ip address anyway
{:bind "192.168.0.212"
:port 7234}
The console prints out it is using the specific host address
❯ clojure -M:repl/rebel
nREPL server started on port 7234 on host 192.168.0.212 -
[Rebel readline] Type :repl/help for online help info
user=>
Cider-connect also finds the specific IP address and can connect to the repl using that IP address..Ah, so --bind
is to set the IP address of the server.
--host
is to specify the IP address of another nrepl process to connect too (nrepl can also act as a client)
Naming of these options are easily confused 🙂
❯ clojure -M:repl/rebel --bind "192.168.0.212"
nREPL server started on port 33237 on host 192.168.0.212 -
[Rebel readline] Type :repl/help for online help info
user=>
I've leaned some new things, thanks for asking the question
(run! f coll)
is (reduce #(f %2) nil coll)
under the hood. Wouldn't it also make sense to also have (run! xf f coll)
be (transduce xf (completing #(f %w)) nil coll)
to avoid intermediate collection generation here as well or would that happen anyway?
I didn't quite get what code produces the intermediate collection that you refer to.
@U06PNK4HG today (run! xf f coll)
doesn't exist, the only signature is (run! f coll)
. Assuming you want to filter the input, this means you have to (run! f (filter pred coll))
for instance. My (perhaps wrong?) understanding is that this then creates intermediary seqs
well you don't have to use a seq op there
the pieces all exist to combine run! with a transducer collection op, question is whether the shorthand is useful enough. not sure, feel free to put on https://ask.clojure.org
Still feels like (run! xf f coll)
could be shorthand for (run! f (eduction xf coll))
but maybe I'm just too lazy 🙂
eduction
, at first, seems to be something additional, not so important. Even in Rich's talk about transducers, he mentions it somewhere at the end, almost like an afterthought. But over time I started using it more and more, and now I wonder if it should have been more prominently pronounced in the whole transducer infrastructure.
And this is a good example of how giving eduction
more stage time and mind share, and maybe a shorter snappier name, could have eliminated the need for such extra arities.
I like to think of it as sort of partial application of xforms to a value without consumption context
It’s a bit tricky to describe for newcomers to transducers, it’s already a quite thick subject
I wonder if turning it around and making eduction
the centerpiece could have made the transducers more approachable. Probably not, but I like to imagine.
https://ask.clojure.org/index.php/13153/could-gain-another-arity-cover-common-case-feeding-eduction
Eduction as a stream of values that gets modified by the functions on top of it. I dunno. At least you get something reified as an intermediate step ("a stream of values") whereas when you are just composing transducers, it is just hot air until you give it both to and fro, and that makes transducers hard to think about.
Is there a way to compose caches with core.cache, e.g. to get an lru cache with a timeout?
Oh, I see I was just missing a page in the docs, they can be composed quite easily.