I'm using deps.edn, trying to require a library into the repl and it results in Execution error (FileNotFoundException) at user/eval3 (REPL:1).
Tried with a few different libraries and the same thing, running on linux. Using different clojure versions doesnt make a difference. Am I missing something?
Can you post your deps.edn and what youβre doing in the repl
{:deps
{selmer {:mvn/version "1.12.33"}}}
(require '[selmer.parse :as sp])
i think you want selmer.parser
with a trailing r
oof i wasnt certainly missing something, thank you for reaffirming my sanity
no worries. i went to the github page and saw what namespaces were there. and saw the easy to make typo
Hi guys, I'm using the clj command line tools and REPL from Powershell commandline in Windows with Clojure 1.10.1 and I've typed (doc clojure.set/intersection)
into the REPL and it just returns nil with no documentation. The only thing I've required into the default user namespace is clojure.specs.alpha aliased as s. Any ideas what's going on?
@flyingpython You'll need to require clojure.set
first
It isn't loaded by default.
Oh and I've just found out Clojure can't find clojure.set when I tried to run the intersection function: Execution error (ClassNotFoundException) at <http://java.net|java.net>.URLClassLoader/findClass (URLClassLoader.java:471).
clojure.set
I'm not sure why it can't find it; I opened clj from a Powershell terminal in a folder I created for practising from the Programming Clojure book
seanc@DESKTOP-30ICA76:~/clojure$ clj
Clojure 1.10.2
user=> (doc clojure.set/intersection)
nil
user=> (clojure.set/intersection #{:a :b} #{:a :c})
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:435).
clojure.set
user=> (require 'clojure.set)
nil
user=> (doc clojure.set/intersection)
-------------------------
clojure.set/intersection
([s1] [s1 s2] [s1 s2 & sets])
Return a set that is the intersection of the input sets
nil
user=> (clojure.set/intersection #{:a :b} #{:a :c})
#{:a}
user=>
^ @flyingpythonLike I said, you need to require clojure.set
first. It is not loaded by default.
OK I didn't realise I thought it would find it if you qualified it with the namespace
Thanks Sean π
No. That happens to work for a few of the core namespaces but you should never rely on it.
Ah OK that is what was confusing me probably because was pretty sure that usually worked
Here's what is currently loaded by default in a REPL:
seanc@DESKTOP-30ICA76:~/clojure$ clj
Clojure 1.10.2
user=> (->> (all-ns) (map str) (sort))
("clojure.core" "clojure.core.protocols" "clojure.core.server" "clojure.core.specs.alpha" "clojure.edn" "clojure.instant" "clojure.java.browse" "<http://clojure.java.io|clojure.java.io>" "clojure.java.javadoc" "clojure.java.shell" "clojure.main" "clojure.pprint" "clojure.repl" "clojure.spec.alpha" "clojure.spec.gen.alpha" "clojure.string" "clojure.uuid" "clojure.walk" "user")
user=>
(but don't rely on that)That is all the ones that you can use without explicitly loading them?
Oh sorry didn't read your first line
That is the ones that you can coincidently use without requiring them. But don't. It could easily change at any time.
OK thank you very much Sean π
It's always better to explicitly require a namespace and give it an alias and use the alias.
Better than using the full namespace name in qualifiers everywhere? Makes the code easier to read. Better than referring a name into your current namespace? Gives a clear indication at the point of use that a name comes from another namespace. Explicitly requiring all the namespaces you use (and giving them aliases) in your ns
form? Provides a straightforward checklist of all your dependencies in one place at the top of the file.
Thanks. It was the βalwaysβ that intrigued me. I tend to most often alias things, but with some of the clojure
ones I donβt. I get confused with aliases like [clojure.string :as str]
and [clojure.set :as set]
, so I require them w/o aliases. In code bases where I am the one making the call, at least. I also refer in some stuff. Not sure what my criteria are, but anyway. π
I will :refer
in a handful of symbols that work better as syntax (like >!
etc from core.async) and we've adopted a set of standard aliases for many of the namespaces we used (enforced by
clj-kondo`). In tests, I tend to refer in all the parts of clojure.test
that I use so there's less "distraction" in the test code. Overall though, I still start from the position that every namespace should be required and aliased -- so, yes, there are exceptions (as there are to every "rule") -- but knowing when to break the rules comes with experience.
Shu-ha-ri
OK will remember this π
yeah, I have made ripley https://github.com/tatut/ripley which tries to be a similar experience to writing reagent but on the backend
Why is it better to alias?
I wonder is there a predicate opposite to nil?
something like not-nil?
or something like that...
quick question about core async, assuming I have a coll and want to push the values to a channel, is the idiomatic way (map #(async/>!! ch %) coll)
or is there something more concise?
Wow. Never ran across run! (ha!). Thanks! And yes, a better match when we don't care about the return values.
I saw the onto-chan
variants, but they all seem to involve concurrency (as in starting threads, go loops) which is not what I wanted here
some?
Is there a recommended way to use date/time in clojure on the JVM?
Interop π
Esp if you are using Java 8 and above
I should say, that's my perferred way π
https://github.com/dm3/clojure.java-time I can recommend that wrapper
I quite like tick - https://github.com/juxt/tick
is there a way to have an add-watch
only on part of an atom? (Say an atom is a map, and I want to see when the value of a key changes, but I'm not concerned about other changes and would like to not do useless computation)
There is nothing like that built into Clojure that I can see. You can begin a watch function with the quickest code that determines whether it is an "interesting" change to you or not, and return as quickly as you can if it is uninteresting.
e.g. the body of the watch function could be something like (if-not (identical? (:foo old-val) (:foo new-val)). <useful code here>)
Or often you would care more about =
than identical?
thanks @andy.fingerhut, I'll use this approach!
I find myself repeatedly importing the same convenience namespaces (like [com.fulcrologic.guardrails.core :refer [>defn >def =>]]
) in each namespace. Is there a way of doing that once and forall?
There might be some IDE hotkey thing that does something like that, but I suspect that most folks probably just copy and paste those from another existing namespace, when creating a new namespace.
Good ol copy and paste, works every time.
Yes a snippet is possible in most ide. It is what i done for test namespace as it is often the same code...
thanks, I can set a snippet in emacs, it's probably a good idea
Look at the to-chan / onto-chan stuff in the core.async api
What function would you use to transform a vector like
[:a :b :c :d :e]
into a list of the consecutive pairs , like
[(:a :b) (:b :c) (:c :d) (:d :e)]
? While it is simple to apply functions I already know , on my learning curve I am currently struggling with inferring which core function I could use to solve specific use cases...(vec (partition 2 1 v))
Here, I think you want onto-chan!!
Where v
is the input.
I knew about partition [n coll]
but overlooked partition [n step coll]
, thanks a lot :)
Hello, I have a question about automatically restarting agents. clojuredocs shows that restart-agent
needs to be called in a separate thread, so shows it being called in a future in the :error-handler
. Before I stumbled across this, I tried supplying this error-handler: (fn [ag ex] (send ag (constantly foo)))
(where foo
is the initial state of the agent), which seems to work fine. Is there any reason to prefer calling restart-agent
in a future to my approach?
have you looked at just using (set-error-mode! ag :continue)
?
I have, but that results in the agent keeping the state it had before the error
In my case, I want to throw the towel in and revert the agent to how it was at the beginning, I think
ok, seems fine to me
thanks π
yeah what I figured as well. Was hoping for a blocking variant but this works. Thanks!
onto-chan!! will block?
oh, I see what you mean
can you get that by taking from the channel returned by onto-chan?
@elegoff760 this fits my style, YMMV, but I found it very useful to read and understand every function here when I was getting started: https://clojure.org/api/cheatsheet
seems like that's the return of the thread fn and all puts should be done by then
I'm an ex-Rails dev looking at adding user auth & roles to a clojure webapp. In rails I'd just use Devise and basically be done with it. I've poked around a bit and found https://github.com/funcool/buddy and https://github.com/cemerick/friend, but neither seems fully featured (though buddy is closer, it still has a lot in the TODO section of the readme) Is there a recommended library for Devise-like functionality that I'm missing or is the standard practice to roll your own?
Nothing like Devise, to my knowledge. Do manual atop buddy.
i'm not aware of a Devise-like library, but it has been some time since i looked
i prefer buddy over friend
thanks for the replies @chrisblom & @claudius.nicolae - both of you prefer buddy over friend - could you say why ?
i found buddy easier to use
it has some pre-built middleware that was easy to integrate: https://github.com/funcool/buddy-auth
I prefer buddy because I'm cargoculting.
But it's also newer (so it had the opportunity to consider what can be improved in friend), and more modular - piece-wise.
And Chas having "left clojure" and https://groups.google.com/g/clojure-sec/c/ceMhYPR0G60.
Something Devise-like could be implemented as a https://github.com/duct-framework/duct module (with buddy for warden, and ring for rack).
thanks for the pointers you two.. much appreciated. I need some hammock time to process π :hammock:
friend is not really maintained anymore, and was forked and updated by clj-commons to fix a CVE in a dependency: https://github.com/clj-commons/friend
Yeah, you can take from the returned channel, but at that point the conciseness vs map is starting to suffer. Anyways, thanks for sorting out the options. Looking at this I think i might stick with map for now.
vs map, run!
is probably preferred for this case btw