Fork me on GitHub
#clojure
<
2022-11-28
>
Nikolas Pafitis12:11:16

How can i specify my project's aliases when I want to get my project's dependency tree with -X:deps tree

Nikolas Pafitis12:11:02

That did the treek

👍 1
marrs12:11:59

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.

p-himik12:11:51

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.

marrs13:11:51

boot.user=> (System/getProperty "java.class.path")
"/usr/bin/boot"

marrs13:11:13

I'm using Boot to provide the repl

marrs13:11:31

There's no boot.clj or anything like that

delaguardo13:11:35

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

delaguardo13:11:29

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

delaguardo13:11:50

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

marrs13:11:21

They probably want to write code 😛

marrs17:11:51

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=>

p-himik18:11:01

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?

p-himik18:11:06

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.

marrs18:11:00

The socket repl is so that I can use it with my IDE

marrs18:11:36

I'll try a different port but I thought 5555 was in the safe range

delaguardo18:11:35

just run from the shell clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"

delaguardo18:11:16

btw which editor are you using?

marrs18:11:30

vim with Fireplace

delaguardo18:11:42

then you need to follow instructions to setup cider-nrepl first

marrs18:11:43

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

marrs18:11:37

Hmm, that might be necessary, although I've been connecting to lein repl just fine. I think that stuff's for more advanced features

marrs18:11:19

ok, so I can connect with netcat, so I guess I'll try setting up cider

marrs18:11:27

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 facepalm

marrs23:11:57

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.

genmeblog14:11:26

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?

Alex Miller (Clojure team)14:11:35

Can you provide repro with more detail?

⬇️ 1
genmeblog14:11:53

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> 

genmeblog14:11:41

Yes, above, I've just replaced previous much longer example with the simpler one.

genmeblog14:11:01

I reload namespace in Emacs via cider-load-buffer (C-c C-k).

genmeblog14:11:22

which calls ns form every time.

Alex Miller (Clojure team)14:11:27

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

Alex Miller (Clojure team)14:11:01

and in both warning cases, you can resolve this by using (ns namespace-2 (:refer-clojure :exclude [dec]))

genmeblog14:11:18

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.

genmeblog14:11:52

User does not know what is injected.

genmeblog14:11:30

The solution is to call unuse-primitive-operators at the end of the namespace, but...

genmeblog14:11:33

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.

Alex Miller (Clojure team)14:11:49

the first warnings exists with 1.11 too, that's not new

genmeblog14:11:15

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)

diego.videco21:11:19

Hey all, is there a way to tell if a lazy-seq is infinite?

Alex Miller (Clojure team)21:11:17

you just walk to the end

Alex Miller (Clojure team)21:11:33

if you never finish, then it's infinite

😂 4
diego.videco21:11:28

I see, any alternatives to calling count on a possibly infinite seq?

diego.videco21:11:35

thanks @U064X3EF3, that may be a good option

phronmophobic21:11:09

as a note, bounded-count can't protect you from infinitely empty lazy sequences:

;; runs forever
(bounded-count 0 (filter (constantly false) (range)))

pizzaspin 2
d._.b23:11:52

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.

thomas09:11:58

Or maybe add things to do to a queue? and take them of the queue as you go?