want you want to assert is that your input only contains a single valid edn form, the way to do that is to not use slurp and read-string, but instead use a reader and read one form, then try and read again and see if you get eof
Hum, ya thats a good idea
Ok, one more question, how can I mock a reader?
Like can I create a reader over a string?
In my test, I don't want to have to use actual files.
https://docs.oracle.com/javase/8/docs/api/java/io/StringReader.html i think
That works!
AFAIK the java team considers each release to be a real release
you can pretty safely just upgrade as soon as new releases are made
its only if you are on a platform that dictates your java version or you plan on paying for paid support that what companies consider LTS in java starts to matter
Hello I try to make a clojurephant gradle project,with both java and clojure clojure has one namespace with gen-class,and i want to use this class from a java file but it says class not found I did
clj -X:new :template clojurephant-clj-app :name myname/myapp
And my project structure is
<project>/
src/
main/
java/
sample_java/
Sample.java (i want to use the class myname.japi from here)
pre/
clojure/
myname/
japi.clj (this is the gen-class)
And i added this in build.gradle after the plugins (saw it from <https://clojurephant.dev/clojurephant/faq.html>)
sourceSets {
pre
main.compileClasspath += pre.output
}
configurations {
preImplementation.extendsFrom implementation
}
The thing that i try to do is possible in clojurephant,and if it is how to do it,thank youthank you , i will not use gradle i think, i will use lein , that i know how to do mixed projects
@takis_ I don't know how many people use Gradle with Clojure but you might try sharing that post into the #gradle channel and see if anyone answers.
thank you
https://github.com/technomancy/leiningen/blob/7f6084d43ef8c8d1c13aa4844ddd7d3b76ce325f/doc/MIXED_PROJECTS.md#interleaving-compilation-steps might be a useful read even if not using that specific approach
Anyone have experience with Clojure + zigbee / smart home to share with me? š
there is a clojure.core
function like some
but that returns the element
rather then (pred element)
There isn't: https://clojure.atlassian.net/browse/CLJ-2056
What about (first (filterā¦))?
AFAICT, it will be enough in the vast majority of all cases. But the ticket above explains why it may not be the best approach in all situations.
Sorry, I should have read it first..
Anyone know a āmodernā way of doing āmodulesā with clojure? Itās mostly about sharing some common dependencies, and being able to build several uberjars at once. Iām currently using lein-modules but it broke with the leiningen 2.9.3.
@gklijs why not just make a library that includes other libs and uberjar that lib?
(if that is what a module is?)
Yes, itās just making it easy with common dependencies and running commands for all modules, like ālein uberjarā but is also easy to script. Iām also not sure how ācommonā leiningen is still with clojure. Could also convert to deps.edn I think..
I usually write (when (pred x) x)
Doesn't work when (false? x)
or (nil? x)
.
when-some
then
But the latter doesn't work with (first ...)
as well.
Yeah, that would do it.
(some #(when-some (pred %) %) ...)
Wait, I'm wrong - that won't work. And when-some
has let
-like bindings.
More like
(:value (some #(when (pred %) {:value %}) values))
(when (some? ...) ...)
my bad
At this point, it becomes simpler to just write a loop
-based function with a clear name. :)
@borkdude You still return false
- and some
ignores it.
some ignores false... hmm, arguably not consistent
Well, it's in its docstring: "Returns the first logical true value [...]"
false
and nil
are the only values that are not logical truths.
user=> (some #(when (false? %) %) [false])
nil
then what was wrong with:
(some #(when (pred %) %) [false 1])
again?If pred
is false?
then you will get nil
whereas you want to get false
.
but some
ignores false
as well, so?
you can never get false
out of some
so I don't see the problem?
Sorry, I'm not sure what's your point.
The initial task - find a way to find an item in collection by a predicate.
My thesis - you cannot use some
as a top-level form for that because it will return nil
for false
.
The initial question was never about some
. :)
The original post:
> there is aĀ clojure.coreĀ function likeĀ someĀ but that returns theĀ elementĀ rather thenĀ (pred element)
Like some
. I rest my case now.
But some
does not return the element when it's false
. Perhaps just differences in our interpretations.
some
also doesn't return (pred element)
in case of false
so that is the like
part ;)
Fair enough.
I thought frequencies-by
(or something similar) was already in clojure.core, as e.g. partition-by
and others, but it isnāt. Has anyone else come across a need for it?
https://gist.github.com/KingCode/30894e53da19d712021906629cf1583c
is there a name for the type of reducing function offers the zero and one arity calls in addition to the standard two arg reduction part? ie, one suitable for use with transduce
?
I use "complete reducing function" as implied by this: https://clojuredocs.org/clojure.core/completing ... But I don't think that's all that common
all else being equal, "transducing function"?
I don't say anything more specific than reducing function
ok. i was wondering if there was some organic term emerging. seems like a very important distinction
Hi all, I am looking for a library offering basic https://en.m.wikipedia.org/wiki/Configuration_management, I need to develop some mechanisms I believe quite general like: commit, diff, tags to manage version, stageing,... very close to mechanisms available in git. For understanding I am building a product referential with their bill of material. When Im looking for these keywords management and configuration are too general words.... so if you are aware of something close to that, I would be interested.
isn't the normal approach here to have a static file with the config data (in eg. JSON or edn) which is checked into git?
in a complex app the config could be a library resource
or is it that a non-programming end user wants to maintain a config, and you want the version control facilities you are used to over that?
Oh no I am not speaking of the configuration of an app but the concepts present in git. In a product referential that concepts are in the core of the app, the ui shows a product in its latest version and objects it refers two. Each evolution is generally concerning more than one object. When you change one object you need to commit all consequences at the same time (kind of transcation).
this is exactly what people us SQL databases for?
oh, my apologies, I didn't realize this was a term of art you were using
No pb, as I said these are two too general words ...
It s not that hard, but it is a little bit technical
And as it is a standard concept I could expect some lib
this might be a good use case for cognitect's datomic, since its model is transactions that add facts to a graph, and queries on some state of that graph
ok, need to have a look, I saw some references to datomic many times (I understood it was rich's answer to db). I will have a look. It's true that all objects are "linked" together. Need to check if those link could be "resolved" together. The resolution mechanism is the one which, in git, helps you to show all the files together, you have the latest commit for each of same. Classical database don't help to do that.
the way datomic works is that you get a handle to a certain transaction representing a state in the db's history, and all queries are done explicitly against that one point in time
so the first class thing is which transaction you are looking at (that's something you always do explicitly before querying)
Definitely I need to have a look
Datomic fits with the requirements as its design can be thought as similar to git. With git we have: pointers (https://git-scm.com/book/en/v2/Git-Internals-Git-References) towards immutable chunk of data (Tree and Blobs). These articles are great to understand git internals: https://maryrosecook.com/blog/post/git-from-the-inside-out, https://git-scm.com/book/en/v2/Git-Internals-Git-Objects, https://medium.com/@pawan_rawal/demystifying-git-internals-a004f0425a70 With Datomic we have Transaction -> Value -> Attribute -> Entity. By the way, https://github.com/tonsky/datascript offers the same Datomic model but in-memory. I believe translating Git design with identifier pointing to Clojure Persistent Data Structure should be quite easy. However, Datomic and Datascript offers a query language (Datalog) that can be quite handy later on. A good intermediary solution should be Datascript data-structure feeded by all the ātransactionsā on a particular product from the referential.
You might also want to look at Crux. It's bitemporality might prove useful for working with versioning.
is there a good way to profile memory usage? The only way i know off hand is to use visualvm and watch the graph as i execute a form. Is there a better way?
(and i mean memory usage of a particular form vs a different form)
Can I rewrite a third-party ex-info
message in such a way that my custom message will be the first thing that is seen in stracktraces/reports?
(e.g. in the repl, test runners)
My intent is making an overly concise message more informative, for fast feedback (i.e. prevent having to read buried ex-data)
I know about the cause
argument, but when using it my custom exception/message will be the second thing being shown, not the first one.
š thanks.
There are always multiple threads and background processes that can affect memory usage so your form will rarely be the only factor But you could use clj-async-profiler to record allocations
what's the best way of writing a spec for a collection that has to start with :and
and continue with a number of things for which I have the sub-spec?
@meditans probably (s/cat :and #{:and} :rest (s/+ :sub-spec))
awesome. thanks!
Can you give a concrete example of what you see and what you want?
@coyotesqrl, I had a look to crux. I understand it as "event oriented", with small independent event. A part of configuration management is close to events, in my understanding, but all configuration management is about tying all that events together, explaining what version of an object is compatible with what version of another object. an be able to manage transactions on that, holding that bunch of objects together. What I read about crux seems not to help me to do that. do you confirm?
In general, the first line of any triaged error message will be about what happened, in what phase, and where (and root cause message in second line)
(Talking about repl usage) but repls in tools vary, pst is different, and tests are yet different
That might be the case. Youād probably have to build extra scaffolding on top. At most, it could give you, āversions at this timeā semantics out of the box.
(set "hello") -> #{\e \h \l \o}
(sorted-set "hello") -> #{"hello"}
@dpsutton How so?
One is a set that has constant membership check and is a set. The other is just a sequence of the items
And that implies you can easily add the items that are already in the collection:
(conj (-> "hello" set sort) \h)
;;=> (\h \e \h \l \o)
Wasn't expecting that. š
You can always do:
(-> "hello" set sort)
So it's not a big deal, just unexpected.user=> (apply sorted-set "hello")
#{\e \h \l \o}
@jeremie I read carefully the articles concerning git, the useful part of git for my use case is in the structure of ref commit trees and blobs. It seems reasonable to implement indeed. So maybe a good shot. Datascript and datomic needs both more investment of my time to understand how it can fit the requirements. Thanks for all for your insightful messages
filter first
will do chunks
(first (filter #(do
(prn %)
(odd? %))
[1 2]))
1
2
=> 1
Maybe we can do something more generic with transducers
(defn transduced-some
"like some, but uses a transducer. Return the first truty value"
[xf coll])
;; possible reimplementation of some
(defn some
[pred coll]
(transduced-some (keep pred) coll))
(defn some-but-returns-el
[pred coll]
(transduced-some (filter pred) coll))
(defn transduced-some
[xf coll]
(let [rf (xf conj)]
(loop [[el & coll] coll
acc []]
(let [acc (rf acc el)]
(if-not (empty? acc)
(first acc)
(when coll
(recur coll acc)))))))
oh, there is a halt-when
Sorting a set is very different from a sorted set though