clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-02-13T00:11:01.055300Z

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

2021-02-13T00:13:45.055500Z

Hum, ya thats a good idea

2021-02-13T00:45:02.055800Z

Ok, one more question, how can I mock a reader?

2021-02-13T00:45:16.056100Z

Like can I create a reader over a string?

2021-02-13T00:45:32.056500Z

In my test, I don't want to have to use actual files.

2021-02-13T00:50:47.056900Z

That works!

šŸ‘ 1
emccue 2021-02-13T03:47:52.057100Z

AFAIK the java team considers each release to be a real release

emccue 2021-02-13T03:48:52.057300Z

you can pretty safely just upgrade as soon as new releases are made

emccue 2021-02-13T03:49:37.057500Z

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

takis_ 2021-02-13T04:33:25.058100Z

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 you

takis_ 2021-02-13T16:08:54.082700Z

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

āœŒļø 1
seancorfield 2021-02-13T06:12:59.060200Z

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

takis_ 2021-02-13T06:14:00.060400Z

thank you

vemv 2021-02-13T06:55:55.061200Z

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

mike_ananev 2021-02-13T07:45:54.064Z

@thegobinath https://clojure.org/guides/learn/namespaces

kwladyka 2021-02-13T12:02:12.065200Z

Anyone have experience with Clojure + zigbee / smart home to share with me? šŸ™‚

souenzzo 2021-02-13T13:42:28.069100Z

there is a clojure.core function like some but that returns the element rather then (pred element)

p-himik 2021-02-13T14:19:06.069200Z

There isn't: https://clojure.atlassian.net/browse/CLJ-2056

2021-02-13T14:45:52.070600Z

What about (first (filterā€¦))?

p-himik 2021-02-13T14:47:00.070800Z

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.

2021-02-13T14:51:52.071100Z

Sorry, I should have read it first..

gklijs 2021-02-13T14:54:41.073400Z

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.

borkdude 2021-02-13T15:02:32.073800Z

@gklijs why not just make a library that includes other libs and uberjar that lib?

borkdude 2021-02-13T15:02:43.074Z

(if that is what a module is?)

gklijs 2021-02-13T15:04:43.075900Z

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

borkdude 2021-02-13T15:11:01.076Z

I usually write (when (pred x) x)

p-himik 2021-02-13T15:12:28.076200Z

Doesn't work when (false? x) or (nil? x).

borkdude 2021-02-13T15:12:56.076500Z

when-some then

p-himik 2021-02-13T15:13:07.076700Z

But the latter doesn't work with (first ...) as well. Yeah, that would do it.

borkdude 2021-02-13T15:13:31.076900Z

(some #(when-some (pred %) %) ...)

p-himik 2021-02-13T15:14:46.077100Z

Wait, I'm wrong - that won't work. And when-some has let-like bindings.

p-himik 2021-02-13T15:15:28.077300Z

More like

(:value (some #(when (pred %) {:value %}) values))

borkdude 2021-02-13T15:16:01.077500Z

(when (some? ...) ...) my bad

p-himik 2021-02-13T15:16:03.077700Z

At this point, it becomes simpler to just write a loop-based function with a clear name. :)

p-himik 2021-02-13T15:16:20.077900Z

@borkdude You still return false - and some ignores it.

borkdude 2021-02-13T15:16:55.078100Z

some ignores false... hmm, arguably not consistent

p-himik 2021-02-13T15:17:45.078300Z

Well, it's in its docstring: "Returns the first logical true value [...]" false and nil are the only values that are not logical truths.

p-himik 2021-02-13T15:18:28.078500Z

user=&gt; (some #(when (false? %) %) [false])
nil

borkdude 2021-02-13T15:19:14.078700Z

then what was wrong with:

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

p-himik 2021-02-13T15:20:05.078900Z

If pred is false? then you will get nil whereas you want to get false.

borkdude 2021-02-13T15:20:30.079100Z

but some ignores false as well, so?

borkdude 2021-02-13T15:21:17.079300Z

you can never get false out of some so I don't see the problem?

p-himik 2021-02-13T15:21:27.079500Z

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.

p-himik 2021-02-13T15:21:59.079800Z

The initial question was never about some. :)

borkdude 2021-02-13T15:22:39.080Z

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.

p-himik 2021-02-13T15:23:22.080200Z

But some does not return the element when it's false. Perhaps just differences in our interpretations.

borkdude 2021-02-13T15:24:11.080400Z

some also doesn't return (pred element) in case of false so that is the like part ;)

p-himik 2021-02-13T15:25:35.080700Z

Fair enough.

2021-02-13T15:30:44.082100Z

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

vemv 2021-02-13T15:51:37.082400Z

https://github.com/polyfy/polylith

dpsutton 2021-02-13T16:25:27.083700Z

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?

Ed 2021-02-14T13:13:00.122600Z

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

2021-02-13T16:30:16.084900Z

all else being equal, "transducing function"?

ghadi 2021-02-13T16:30:22.085100Z

I don't say anything more specific than reducing function

dpsutton 2021-02-13T16:32:07.085700Z

ok. i was wondering if there was some organic term emerging. seems like a very important distinction

caumond 2021-02-13T16:54:03.094300Z

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.

2021-02-13T17:01:37.094400Z

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?

2021-02-13T17:01:59.094600Z

in a complex app the config could be a library resource

2021-02-13T17:02:57.094800Z

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?

caumond 2021-02-13T17:27:54.095100Z

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

2021-02-13T17:30:22.095300Z

this is exactly what people us SQL databases for?

2021-02-13T17:31:56.095800Z

oh, my apologies, I didn't realize this was a term of art you were using

caumond 2021-02-13T17:32:51.096Z

No pb, as I said these are two too general words ...

caumond 2021-02-13T17:33:39.096200Z

It s not that hard, but it is a little bit technical

caumond 2021-02-13T17:34:59.096600Z

And as it is a standard concept I could expect some lib

2021-02-13T17:40:43.096800Z

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

caumond 2021-02-13T17:48:48.097200Z

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.

2021-02-13T17:57:42.097400Z

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

2021-02-13T17:58:34.097600Z

so the first class thing is which transaction you are looking at (that's something you always do explicitly before querying)

caumond 2021-02-13T18:00:19.097800Z

Definitely I need to have a look

2021-02-13T18:23:53.098Z

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.

R.A. Porter 2021-02-13T18:41:59.098700Z

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

dpsutton 2021-02-13T19:19:31.099900Z

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?

dpsutton 2021-02-13T19:19:48.100300Z

(and i mean memory usage of a particular form vs a different form)

vemv 2021-02-13T19:29:06.104200Z

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.

vemv 2021-02-14T08:42:54.121500Z

šŸ‘ thanks.

jumar 2021-02-13T19:31:48.107200Z

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

william 2021-02-13T19:38:02.108500Z

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?

borkdude 2021-02-13T19:38:59.109200Z

@meditans probably (s/cat :and #{:and} :rest (s/+ :sub-spec))

šŸ™Œ 1
dpsutton 2021-02-13T19:39:32.109400Z

awesome. thanks!

alexmiller 2021-02-13T20:27:55.110200Z

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

caumond 2021-02-13T20:27:57.110400Z

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

alexmiller 2021-02-13T20:29:09.112Z

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)

alexmiller 2021-02-13T20:30:09.113300Z

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

R.A. Porter 2021-02-13T20:32:30.113500Z

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.

danielglauser 2021-02-13T22:36:16.114500Z

(set "hello") -&gt; #{\e \h \l \o}
(sorted-set "hello") -&gt; #{"hello"}

danielglauser 2021-02-14T17:57:56.133400Z

@dpsutton How so?

dpsutton 2021-02-14T17:58:49.134500Z

One is a set that has constant membership check and is a set. The other is just a sequence of the items

jumar 2021-02-16T08:43:31.184100Z

And that implies you can easily add the items that are already in the collection:

(conj (-&gt; "hello" set sort) \h)
;;=&gt; (\h \e \h \l \o)

danielglauser 2021-02-13T22:36:31.114600Z

Wasn't expecting that. šŸ™‚

danielglauser 2021-02-13T22:37:51.114800Z

You can always do:

(-&gt; "hello" set sort)
So it's not a big deal, just unexpected.

borkdude 2021-02-13T22:38:36.115Z

user=&gt; (apply sorted-set "hello")
#{\e \h \l \o}

1
caumond 2021-02-13T22:43:05.115300Z

@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

souenzzo 2021-02-13T22:57:01.115500Z

filter first will do chunks

(first (filter #(do 
                  (prn %)
                  (odd? %))
               [1 2]))
1
2
=&gt; 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))

souenzzo 2021-02-13T23:02:08.115700Z

(defn transduced-some
  [xf coll]
  (let [rf (xf conj)]
    (loop [[el &amp; coll] coll
           acc []]
      (let [acc (rf acc el)]
        (if-not (empty? acc)
          (first acc)
          (when coll
            (recur coll acc)))))))

souenzzo 2021-02-13T23:04:45.115900Z

oh, there is a halt-when

dpsutton 2021-02-13T23:33:37.116600Z

Sorting a set is very different from a sorted set though