Fork me on GitHub

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.


That works!

šŸ‘ 3

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

 (i want to use the class myname.japi from here)
          japi.clj (this is the gen-class)

And i added this in build.gradle after the plugins (saw it from )

sourceSets {
  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 you


thank you , i will not use gradle i think, i will use lein , that i know how to do mixed projects

āœŒļø 3

@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.


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)


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


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. :)


@U04V15CAJ 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])


then what was wrong with:

(some #(when (pred %) %) [false 1])


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.


filter first will do chunks

(first (filter #(do 
                  (prn %)
                  (odd? %))
               [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


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


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: ... 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, 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 ( towards immutable chunk of data (Tree and Blobs). These articles are great to understand git internals:,, With Datomic we have Transaction -> Value -> Attribute -> Entity. By the way, 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.

R.A. Porter18:02:59

You might also want to look at Crux. It's bitemporality might prove useful for working with versioning.


@U01GXCWSRMW, 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?

R.A. Porter20:02:30

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.


@U0FTDSQQ3 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


As it sounds pretty industrial, I feel there is most likely a Java framework or library for it. I'd look for that as well.


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?


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


awesome. thanks!


(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.

Alex Miller (Clojure team)20:02:55

Can you give a concrete example of what you see and what you want?

Alex Miller (Clojure team)20:02:09

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)

Alex Miller (Clojure team)20:02:09

(Talking about repl usage) but repls in tools vary, pst is different, and tests are yet different


Thanks for the response! Here's a repro:

~ $ clj
Clojure 1.10.2
user=> (throw (ex-info "Improved error message" {} (ex-info "Original error message" {})))
Execution error (ExceptionInfo) at user/eval1 (REPL:1).
Original error message
I want to see Improved error message because in my domain, the Original error message that comes from a third-party is overly concise I understand why Original error message is being show first - it's technically its root cause. But perhaps there's some way to hack things here (without losing the original exception either)?

Alex Miller (Clojure team)06:02:03

the error triage stuff will always prefer the root cause so you would need to replace rather than wrap in the throw


šŸ‘ thanks.


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

šŸ™Œ 3

(set "hello") -> #{\e \h \l \o}
(sorted-set "hello") -> #{"hello"}


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}


Sorting a set is very different from a sorted set though


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)