This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-28
Channels
- # adventofcode (2)
- # announcements (4)
- # babashka (34)
- # beginners (44)
- # biff (5)
- # calva (8)
- # cider (4)
- # clj-kondo (5)
- # clj-on-windows (5)
- # clojure (57)
- # clojure-art (1)
- # clojure-denmark (2)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-seattle (1)
- # clojure-uk (2)
- # clojurescript (20)
- # cursive (6)
- # datomic (1)
- # emacs (6)
- # events (5)
- # fulcro (22)
- # helix (5)
- # hyperfiddle (5)
- # jobs (1)
- # joyride (2)
- # lsp (8)
- # malli (8)
- # off-topic (30)
- # pathom (8)
- # pedestal (1)
- # portal (5)
- # proton (1)
- # rdf (2)
- # re-frame (4)
- # releases (1)
- # remote-jobs (1)
- # reveal (8)
- # xtdb (5)
How can i specify my project's aliases when I want to get my project's dependency tree with -X:deps tree
Can anyone advise me? I've been doing some programming in a nrepl and I want to split some of the code out into its own namespace. I still want to develop in the repl; I just want to (require '[myns])
and then be able to evaluate (myns/myfn)
from there on. There doesn't seem to be any straight forward way of doing this. Moving the code to src/myns.clj
doesn't work. Adding a deps.edn
with {:paths [:src]}
doesn't help either. Evaluating the require
statement just returns a java.io.FileNotFound error.
I don't want a "project" at this point. I don't want to have to depend on lein or boot, or have to build jars and I have no external dependencies to worry about. I just need to be able to move some code out of the file I'm working in so that I don't have to manually evaluate all the functions whenever I start a repl.
What are the local resources on your classpath? You can check with (System/getProperty "java.class.path")
where you split its output by ":"
and remove all jars.
if you define vars only in running repl then you don't need to call require
the code is already "required" and available via qualified var like myns/myfn
beware that without "project" you wouldn't have access to any dependencies except provided by clojure itself
you could also look at beginners guide. There is a new way to manage clojure "project" without having project at all. It is called Clojure CLI
this one is very useful. and I would definitely recommend to read throw other pages as well. For some reason a lot of beginners skip them idkw but there are answers on almost all early questions about the language and its ecosystem
yeah, sure
ok, so I've jumped down the clj
rabbit hole. I'm now trying to serve a repl via a socket using the instructions in that page. Unfortunately, anything that tries to connect to the socket just hangs without error. Running the server manually in the repl also yields no errors. Here's the code:
user=> (clojure.core.server/start-server {:name "foo" :port 5555 :accept 'clojure.core.server/repl :server-daemon false})
#object[java.net.ServerSocket 0x1869f114 "ServerSocket[addr=localhost/127.0.0.1,localport=5555]"]
user=>
Works on my end just fine:
$ clj
Clojure 1.11.1
user=> (clojure.core.server/start-server {:name "foo" :port 5555 :accept 'clojure.core.server/repl :server-daemon false})
#object[java.net.ServerSocket 0x5a12c728 "ServerSocket[addr=localhost/127.0.0.1,localport=5555]"]
user=>
in one terminal with
$ telnet 127.0.0.1 5555
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
user=> 1
1
user=> 2
2
user=>
in the other.
Could it be that your local firewall somehow doesn't like 5555 on localhost?But also, that seems to be completely unrelated to your initial question as you don't need a socket REPL for that - a plain local REPL works just fine, one that you used to call start-server
in the first place.
So if you for some reason still want to launch a socket REPL and can't do it, I'd suggest asking a separate question so that more people see it. Or maybe there's already some answer here - I'd try searching on Slack as well.
just run from the shell clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
btw which editor are you using?
then you need to follow instructions to setup cider-nrepl first
I've been using that and lein repl :connect localhost:5555
as a client. I don't have telnet installed but I'll try something like that in a mo
Hmm, that might be necessary, although I've been connecting to lein repl just fine. I think that stuff's for more advanced features
oh, I'm under the misaprehension that nrepl means clojure.core.repl over a network and it doesn't. It's a separate package. This might be the reason I can't connect
Thanks everyone who helped. Got everything sorted. This was my final deps.edn. I think it would have also worked with nrepl/nrepl
in place of cider/cider-nrel
but I figured the Cider stuff will be useful eventually
{:paths ["src"]
:aliases {:cider-clj {:extra-deps {org.clojure/clojure {:mvn/version "1.10.1"}
cider/cider-nrepl {:mvn/version "0.28.5"}}
:main-opts ["-m"
"nrepl.cmdline"
"--middleware"
"[cider.nrepl/cider-middleware]"]}
}}}}
Run clj -M:cider-clj
to run the nrepl. Everything works as hoped for.Latest changes (https://clojure.atlassian.net/browse/CLJ-2711) in Clojure 1.12.0-alpha1 introduced some problem regarding reloading namespace. When I overwrite some clojure.core
symbols (via ns-unmap
and require :refer [...]
) and call (ns ...)
I'm getting a bunch of warnings about var replacement. How to deal with this?
Here is the minimal example:
user> (ns namespace-1 (:refer-clojure :exclude [dec]))
nil
namespace-1> (def dec #(- % 1))
#'namespace-1/dec
namespace-1> (ns namespace-2)
nil
namespace-2> (ns namespace-2)
nil
namespace-2> (ns-unmap *ns* 'dec)
nil
namespace-2> (require '[namespace-1 :refer [dec]])
nil
namespace-2> (ns namespace-2)
WARNING: dec already refers to: #'namespace-1/dec in namespace: namespace-2, being replaced by: #'clojure.core/dec
nil
namespace-2>
I think that can be slimmed down a bit more:
(ns namespace-1 (:refer-clojure :exclude [dec]))
(def dec #(- % 2))
(ns namespace-2)
(require '[namespace-1 :refer [dec]])
WARNING: dec already refers to: #'clojure.core/dec in namespace: namespace-2, being replaced by: #'namespace-1/dec
(ns namespace-2) ;; warns
WARNING: dec already refers to: #'namespace-1/dec in namespace: namespace-2, being replaced by: #'clojure.core/dec
and in both warning cases, you can resolve this by using (ns namespace-2 (:refer-clojure :exclude [dec]))
Right, but the issue is (again) with fastmath.core/use-primitive-operators
(or primitive-math/use-primitive-operators
) which is convenient way to inject replacements for set of operators.
The solution is to call unuse-primitive-operators
at the end of the namespace, but...
seems right to me
Possibly other libraries use similar trick to replace vars. I don't know how this namespace manipulation method is common. If it's only fastmath
I can deal with it. I mean, I can reorganize the code to avoid warnings in fastmath
and related libs.
the first warnings exists with 1.11 too, that's not new
Yes, true, fastmath.core
uses :refer-clojure :exclude
cause I know what is going to be redefined. Also primitive-math
does (https://github.com/clj-commons/primitive-math/blob/master/src/primitive_math.clj#L3)
Hey all, is there a way to tell if a lazy-seq is infinite?
you just walk to the end
I see, any alternatives to calling count
on a possibly infinite seq?
https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/bounded-count
thanks @U064X3EF3, that may be a good option
as a note, bounded-count
can't protect you from infinitely empty lazy sequences:
;; runs forever
(bounded-count 0 (filter (constantly false) (range)))
Hello all, I'm working on a problem where there's an initial network call that collects some information, and from that information, a tree of tasks (more network calls and db access) is spawned. I'd like to be able to inspect the current status of all branches and leaves as it runs such that I can represent how branches are progressing (when all leaves have completed or failed, a branch is marked as being finished). In some ways you might think of it as a parallel test runner where you can watch the progress, or a process tree. I'm wondering if there's prior art in clojure for building this sort of thing before I get too far down the rabbit hole.