clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
seancorfield 2021-05-26T00:08:36.404200Z

@maxminos.1 :local-repo tells Maven (lein) where to cache dependencies that it downloads. Normally that’s the ~/.m2 folder. :repositories defines one or more named locations to go look for dependencies to download — normally you have central, clojars, but you can add more places to look, e.g., if you have a private Maven repo or you want to host dependencies on S3.

seancorfield 2021-05-26T00:09:18.405Z

So if you want Leiningen to cache the JARs it downloads in a different place to usual, that’s :local-repo. What is your actual use case?

max minoS 2021-05-26T00:14:50.408100Z

@seancorfield I am just trying to keep my ~/.m2 folder confined within ~/.cache/m2 , additionally, I have also set my maven localRepositories to the cache directory by the settings.xml, and i've also set BOOT_LOCAL_REPO to ~/.cache/m2/repository I'm just not sure how to check whether the directories are for m2/repository or just m2/

seancorfield 2021-05-26T00:26:43.408900Z

According to the Leiningen source, it looks like the default is ~/.m2/repository so that’s the structure it will expect in :local-repo.

seancorfield 2021-05-26T00:27:31.409700Z

(tools.deps.alpha has the same default for the Clojure CLI so at least that looks consistent)

max minoS 2021-05-26T00:27:48.410200Z

perfect! that's what i have it set as, what about the :repositories "local"shown in the link?

max minoS 2021-05-26T00:27:53.410500Z

should I just remove that?

seancorfield 2021-05-26T00:28:35.411100Z

If you don’t need to search any repos beyond Maven Central and Clojars, you can remove that.

👍 1
seancorfield 2021-05-26T00:29:10.411800Z

That is terrible documentation BTW. It references #= which is undocumented and should not be used.

seancorfield 2021-05-26T00:29:56.412500Z

I’m pretty sure the clojure package it mentions on that page is not an official package and would conflict with the official Clojure CLI.

max minoS 2021-05-26T00:30:16.412800Z

what should I use instead of #=?

seancorfield 2021-05-26T00:32:02.414200Z

I’m not sure what Leiningen allows for in profiles.clj. I know that you can just “escape” executable code in project.clj. You’d best ask in #leiningen if no one here knows how to put dynamic code in ~/.lein/profiles.clj — I haven’t used Leiningen for years.

seancorfield 2021-05-26T00:32:40.414800Z

(although since it is your user config file, you could just hardcode the full path without dynamic evaluation)

max minoS 2021-05-26T00:33:03.415Z

thanks alot! i will look into it

seancorfield 2021-05-26T00:33:25.415400Z

Why do you want to change Leiningen’s defaults?

max minoS 2021-05-26T00:34:03.416300Z

just to keep my home folder clean, it also happens to help me understand how it works a little better and pushes me to look at whats going on behind the scenes

seancorfield 2021-05-26T00:36:28.417900Z

Oh, OK, you said above… sorry. I guess that "local" repo is so that it would look in your original home .m2/repository for anything already downloaded? That wiki page is not very helpful.

🙏 1
quoll 2021-05-26T01:31:56.418100Z

Scratching my head as to where I learned this if it’s undocumented. I know I’ve read the sources, but I thought I saw it somewhere else first

quoll 2021-05-26T01:33:37.418300Z

Never mind… I wrote it down in a note that I last updated in April 2012. Maybe I saw it mentioned at the 2011 Conj

emccue 2021-05-26T03:16:26.418600Z

has anyone kept track of attempts to make something like Pheonix Live View/LiveWire in clojure

emccue 2021-05-26T17:37:23.460900Z

Just saw this - thank you

emccue 2021-05-26T17:37:49.461100Z

i'm going to read their impls and maybe find a way to contact the authors about where their heads are at

2021-05-26T18:07:36.461400Z

You can ping me if you have any questions about liveview-clj. It is written by my former teammate and some problems we discussed together

emccue 2021-05-26T18:32:46.461600Z

I'll keep that in mind - this might be a weekend, not weeknight project though so it might be a bit

emccue 2021-05-26T03:17:09.419500Z

I keep thinking it would be a great demo for loom stuff but I feel like I am missing some essential bits of design to actually make it work

emccue 2021-05-26T03:18:37.420100Z

I can throw up a simple demo that just uses https://github.com/juji-io/editscript with reagent, but that feels...lacking

emccue 2021-05-26T03:22:00.420500Z

(maybe even an actual use case for https://akka.io/)

2021-05-26T03:43:06.428200Z

I have a huge reducing function that operates on a sequences of maps and I want to introduce some functionality using a very small subset of data involved in the sequence of maps or the initial reduce state. The functionality could be capture pretty cleanly as a transducer. However, I cannot use a separate transducing context in the api I'm using, I can only provide a single reducing function. I keep wanting to make a "dummy" reducing function that just spits out the latest result from a transducer, and stick that in the reducing function, like this:

(let [xf (comp
           (map :val)
           (dedupe)
           (partition-all 2)
           (map #(reduce + %)))
      rf (xf (fn [acc x] x))
      states [{:val 1} {:val 2} {:val 3} {:val 4}]]
  (reduce
    (fn [acc x]
      (update acc :sum rf x))
    {:val 0}
    states))
This seems wrong because the rf here is stateful in a way that's not obvious or constrained like other transducing contexts. But the alternative seems to be to use the acc value passed to the reducing function to store a bunch of intermediate values, and then sort of re-implement the transducer functionality on top of that. This seems more correct but also doesn't feel great because I'm reinventing a lot of wheels (`dedupe`, partition, etc) and just "polluting" the acc map with implementation details. Any thoughts on this? How would you handle this situation? Edit: Also, in the real version, it's not a reduce but a process that happens over time that I can provide a (fn [acc x]) to

Ed 2021-05-26T11:10:02.437100Z

not sure I see the advantage of separating the update, outside of the rf ... unless there's something much more complex going on I'm not sure there's any advantage of not doing this:

(let [xf (comp
            (map :val)
            (dedupe)
            (partition-all 2)
            (map #(reduce + %)))
        rf (xf (fn [acc x] (assoc acc :sum x)))
        states [{:val 1} {:val 2} {:val 3} {:val 4}]]
    (reduce
     rf
     {:val 0}
     states))
which is what I assume you mean by "But the alternative seems to be to use the acc value passed to the reducing function". I think that the point of the reducing function being constructed inside the transducing context is that it's coupled to the value that it's reducing into. Here that's rf and {:val 0}. I'm totally sure I understand your problem tbh 😉

👍 1
Ed 2021-05-26T11:12:04.437300Z

and yeah ... there's an xforms/last - but I'm not sure it's worth adding the lib for just that one fn 😉

Ed 2021-05-26T11:15:07.437500Z

and you're not handling the completion case, right? ... I'm guessing that's out of your control, but that'll impact the behaviour of the statefull transducers in your process, right?

Ben Sless 2021-05-26T05:53:56.428800Z

I'm not sure, but if I cross my eyes a little it looks like reductions

👍 1
Ben Sless 2021-05-26T05:59:35.429Z

maybe something from xforms?

2021-05-26T06:05:23.431500Z

anyone having experience with clojure manifold library (especially the streams) ? i was creating a kafka stream construct using the manifold streams

(defn kafka-stream
  [config topic]
  (let [output (s/stream 100)
        consumer (KafkaConsumer. (kuk/as-properties config))]
    (future
      (s/on-closed output (fn [] (.close consumer)))
      (d/loop []
        (.subscribe consumer [topic])
        (let [msgs (.poll consumer (:poll-timeout config 2000))]
          (doseq [m msgs]
            @(s/put! output m))
          (d/recur))))))
but i had a hard time trying to make the (.poll) call lazy. i.e. i wanted the consumer loop to begin only when some sink connected to it. if anyone with akka stream experience can relate to me. i really doubt if it is possible since manifold stream seems like a push based system as opposed to pull based system (which akka is)

2021-05-26T06:13:18.431700Z

Maybe worth to look at KafkaStreams framework

2021-05-26T06:18:22.431900Z

@delaguardo actually we were building out a layer that allows us to have pluggable sources

2021-05-26T06:20:31.432200Z

Then I can recommend KafkaConnect. Used it as a pluggable source with common sink

👍 1
Tim Brown 2021-05-26T08:34:38.433400Z

Hey all, I'm just starting with deps.edn, and I'm trying to depend on a pom type dependency. Is this possible?

&lt;!-- <https://mvnrepository.com/artifact/com.ocadotechnology/OcavaParent> --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.ocadotechnology&lt;/groupId&gt;
    &lt;artifactId&gt;OcavaParent&lt;/artifactId&gt;
    &lt;version&gt;10.10.14&lt;/version&gt;
    &lt;type&gt;pom&lt;/type&gt;
&lt;/dependency&gt;

p-himik 2021-05-26T08:53:40.433500Z

It is possible.

Tim Brown 2021-05-26T09:26:33.433900Z

from those docs (my emphasis): > Local project coordinate: {:local/root "/path/to/project"} > Optional key :deps/manifest > Specifies the project manifest type > Default is to auto-detect the project type (currently either :deps or :pom) the type of the project isn't mentioned in the "maven coordinate" section above it 😞

Tim Brown 2021-05-26T09:27:50.434200Z

and I have tried this too (documentation ignored)

p-himik 2021-05-26T09:31:47.434400Z

I'm not sure where the misunderstanding is. Maven is based on POM. Maven artifacts, AFAIK, cannot be uploaded without POM files.

p-himik 2021-05-26T09:32:09.434600Z

You need :mvn/version, not :local/root.

p-himik 2021-05-26T09:32:51.434800Z

Or do you want to depend on a local JAR with a POM file in it?

Tim Brown 2021-05-26T09:34:58.435Z

there is a pom-only distribution method for maven; this is a "parent" project that doesn't have a jar artifact

Tim Brown 2021-05-26T09:54:56.435200Z

{
:deps {
       ;; <https://mvnrepository.com/artifact/com.ocadotechnology/OcavaParent>
       com.ocadotechnology/OcavaParent {:mvn/version "10.10.14" :deps/manifest :pom}
       }

}
$ clj
Error building classpath. Could not find artifact com.ocadotechnology:OcavaParent:jar:10.10.14 in central (<https://repo1.maven.org/maven2/>)
there is no jar file... the only artifact would be: com.ocadotechnology:OcavaParent:pom:10.10.14

p-himik 2021-05-26T09:55:51.435400Z

Ah, apologies - I didn't realize it had that &lt;typ&gt; . Almost never see it. No, it's not supported. You have to list all required dependencies manually.

Tim Brown 2021-05-26T09:58:31.435600Z

Grrr... frustrating because the authors have already done that! Oh well, I think I might try and do this locally, not using a remote mvn.

p-himik 2021-05-26T10:01:09.435800Z

If you really need all of the dependencies from that pom - why is it a problem to just list them out explicitly in your deps.edn?

p-himik 2021-05-26T10:01:44.436Z

For context, here's where Alex Miller mentions that it's not supported: https://clojurians-log.clojureverse.org/tools-deps/2020-07-29

Tim Brown 2021-05-26T10:01:54.436200Z

thanks for the reference.

Tim Brown 2021-05-26T10:02:27.436400Z

Regards the previous question... I think it's a case of not duplicating effort.

p-himik 2021-05-26T10:05:48.436600Z

It's also the case of implicit vs explicit. :) IMO, and Alex seems to have the same opinion, if you depend on something, that exact dependency should be in deps.edn. And not something else that also depends on it. But opinions can be different, of course.

Tim Brown 2021-05-26T10:20:08.436800Z

I get that... I've watched Alex speaking about it. I'll be depending on only that library (for now); so I intend that it is that library that manages its dependencies (even if it is through the sub-wonderful maven strategy). I actually feel that I'm not entitled to make those choices for the library. Of course when I need one of those dependencies explicitly... then I'll be explicit.

👍 1
p-himik 2021-05-26T11:45:33.437700Z

@tim595 Oh, I just noticed that Ocava deals with simulations, and I recently became interested in the general topic of simulations, with the inline towards biological processes. Do you maybe have any recommendations in literature, tools, or something else for a beginner in the area?

Tim Brown 2021-05-26T11:55:02.438Z

As far as I know, Ocava is concerned with Discrete Event Simulations; I'm not sure if the documentation and sample code in that project gives you a good introduction. From the readme: > Ocava was created by https://www.ocadotechnology.com/'s Simulation Team after they successfully implemented a simulation and testing framework in order to test a radical proof of concept fulfilment warehouse proposal. I can vouch for it being a solid tool/library to base a Java product on. I want to see if I can use it for “stateless” simulations (value-based or even data-driven clojurey goodness). Our current product is stateful, and I don’t think it has to be

Tim Brown 2021-05-26T11:55:09.438200Z

except for the bits that have to be 😉

p-himik 2021-05-26T11:57:02.438400Z

Gotcha. Thanks!

Tim Brown 2021-05-26T11:58:18.438600Z

IIRC there's a reference at the bottom of the wikipedia page for DES, titled along the lines of "simulation for beginners"

Tim Brown 2021-05-26T11:59:55.439100Z

Not DES... but related-ish

p-himik 2021-05-26T12:05:02.439300Z

Oh, nice! Will add it to the list.

emccue 2021-05-26T12:05:07.439600Z

https://clojure.atlassian.net/browse/CLJ-2065

emccue 2021-05-26T12:05:12.439800Z

running into this in the wild

emccue 2021-05-26T12:05:56.440100Z

(ns ssr
  (:require
   [cognitect.transit :as transit]
   [editscript.core :as editscript]
   [editscript.edit :as edit]
   [hiccup.core :as hiccup]))

(def current-state (atom [:div]))

(println (type @current-state))

(defn render
  ([]
   (hiccup/html @current-state))
  ([new]
   (hiccup/html
    (swap! current-state
           (fn [html-1]
             (let [diff (editscript/diff html-1 new)]
               (editscript/patch html-1 diff)))))))

(render [:div "b"])
(println (type @current-state))
(render [:div "c"])
(println (type @current-state))

emccue 2021-05-26T12:06:04.440400Z

clojure.lang.PersistentVector
clojure.lang.APersistentVector$SubVector
Syntax error (IllegalArgumentException) compiling at (src/clj/ssr.clj:24:1).
No implementation of method: :kv-reduce of protocol: #'clojure.core.protocols/IKVReduce found for class: clojure.lang.APersistentVector$SubVector

emccue 2021-05-26T12:11:17.440900Z

i see the workaround so this won't hard block me, but still frustrating

alexmiller 2021-05-26T12:36:37.441400Z

You can vote here https://ask.clojure.org/index.php/3319/reduce-kv-fails-on-subvec?show=3319#q3319

emccue 2021-05-26T13:53:33.441800Z

voted

Joel 2021-05-26T14:36:28.444400Z

I've been writing functions that "pair/tuple" matches so that i can work on the combination. For example finding a match with an element in a list and returning [element match]. I could write a (tuple-match match-fn element collection) I suppose to simplify this process, but just wondering if there's already something idiomatic.

emccue 2021-05-26T14:38:51.445300Z

if you already have element in scope, is there any reason not to

emccue 2021-05-26T14:39:35.446200Z

[element (first (filter (partial match-fn element)) coll)]

emccue 2021-05-26T14:39:59.446400Z

or

emccue 2021-05-26T14:40:15.446800Z

(if-let [match (first (filter (partial match-fn element) coll))]
  [element match])

Derek Passen 2021-05-26T14:44:41.448Z

(some (fn [element] (when (condition? element match) [element match])) coll)

emccue 2021-05-26T14:50:02.448400Z

(if-let [match (some (partial match-fn element) coll)]
  [element match])

Derek Passen 2021-05-26T14:50:26.448600Z

🙂

Joel 2021-05-26T14:52:03.449600Z

good suggestions. i think part of the trick for me is to learn more verbs. I forget "keep" instead of (remove nil? (map... )) some instead of (first (filter...

borkdude 2021-05-26T15:19:31.450700Z

Is it possible to make lein uberjar aot compilation behave more like a simple (compile 'foo.bar) instead of that it iterates over a series of namespaces? that iterating causes some weird edge cases sometimes I think

borkdude 2021-05-26T15:20:05.451100Z

"yeah, just use deps.edn", at some point yes, but not right now for this project

alexmiller 2021-05-26T15:21:27.451700Z

clojure.lang.Compile is a Java class in Clojure that basically does that

alexmiller 2021-05-26T15:22:24.452900Z

it's actually used by the Clojure build to compile Clojure itself and I don't honestly know if I'd consider it part of the "public API" of Clojure, but it does exist

borkdude 2021-05-26T15:22:41.453500Z

well, I mean, when I run lein uberjar it says:

Compiling sci.addons
Compiling sci.addons.future
Compiling sci.core
but honestly, it only needs to compile one namespace and Clojure takes care of the rest

alexmiller 2021-05-26T15:22:54.453700Z

it's a main that takes a list of namespaces to compile

borkdude 2021-05-26T15:23:44.454200Z

perhaps it's just :aot :all -> :aot [sci.impl.main] ?

alexmiller 2021-05-26T15:24:06.454500Z

^^ I think that works too

borkdude 2021-05-26T15:25:14.455500Z

I think I have a different problem. I get:

Caused by: java.lang.LinkageError: loader clojure.lang.DynamicClassLoader @498b697 attempted duplicate class definition for sci.impl.namespaces$copy_var. (sci.impl.namespaces$copy_var is in unnamed module of loader clojure.lang.DynamicClassLoader @498b697, parent loader clojure.lang.DynamicClassLoader @77978658)
I have some conditional where I define copy-var based on some env variable but it seems something is odd when AOT-ing this

borkdude 2021-05-26T15:29:48.456600Z

well, I'll rewrite it.

borkdude 2021-05-26T15:32:29.457Z

fixed

borkdude 2021-05-26T15:38:22.457600Z

the compilation thing caused issues in some other context, but the :all -&gt; [sym] works well, so I also changed this

NoahTheDuke 2021-05-26T15:43:11.458600Z

is one of the edge cases you mentioned the issue where records/protocols can become redefined mid-compilation?

alexmiller 2021-05-26T15:49:36.459200Z

That’s really the main one

👍 1
NoahTheDuke 2021-05-26T15:51:23.459900Z

wish i’d known the answer was this easy two years ago, lol. would have saved me a lot of heartbreak and work

ghadi 2021-05-26T15:51:59.460Z

is there a common scenario that causes this? I'm not sure I follow the specifics

alexmiller 2021-05-26T15:57:52.460200Z

https://clojure.atlassian.net/browse/CLJ-1544

borkdude 2021-05-26T19:30:09.462900Z

@nbtheduke I have seen some weird segfaults or "no offset for this method" / "should not reach here" exceptions with this using GraalVM

👍 1
borkdude 2021-05-26T19:30:35.463300Z

could be related to the record/protocol stuff

alexmiller 2021-05-26T19:49:31.463600Z

that seems unlikely?

alexmiller 2021-05-26T19:50:21.464200Z

you typically see this problem during compilation due to the in memory classes. not sure how it would be possible to see post-compilation in something like graal

borkdude 2021-05-26T20:31:11.465500Z

@alexmiller I'm not sure either, but I've seen this in multiple projects where the way lein compiles with :aot :all gives weird issues which was solved by simplifying that compilation using just one top namespace

alexmiller 2021-05-26T20:53:35.466100Z

I've seen it in aot compilation, just don't understand how that could impact graal

borkdude 2021-05-26T20:56:50.466300Z

me neither, except that graal uses the AOT-ed bytecode and maybe that didn't work with the JVM either, it happened now and then in CI, randomly

alexmiller 2021-05-26T21:02:18.467100Z

if the compile succeeds, you have not encountered this issue (it's really a problem in the runtime classloader during compilation)

alexmiller 2021-05-26T21:02:43.467400Z

at least, as far as I understand it

borkdude 2021-05-26T21:03:13.468100Z

ok, then it was something else, but I just know that getting rid of the obsolete compiles fixed it

borkdude 2021-05-26T21:03:32.468700Z

at least, the problem didn't occur again. fixed is maybe too strong ;)

2021-05-26T21:33:49.470Z

a lot of projects have issues with how their namespaces are setup such that :aot :all can result in things like defprotocols and defrecords being compiled multiple times

2021-05-26T21:35:50.471100Z

lein's behavior with :aot :all is just kind of really bad, it really wants to believe it can compile each namespace one at a time, when of course that is not how aot compilation works

2021-05-26T21:37:08.472400Z

and at least at one point the order in which :aot :all compiles namespaces was not fixed, so on different oses, different versions of java, etc, you might end up compiling in a different order, where things happened to work one way but not in another

max minoS 2021-05-26T23:11:52.474Z

I am following the modern-cljs tutorial (https://github.com/magomimmo/modern-cljs/), and still on the first one, but for some reason when I boot cljs target and open the index.html of the target, it gives me this error in the console: Uncaught Error: Undefined nameToPath for modern_cljs.core instead of a "Hello, world"

max minoS 2021-05-27T21:25:11.060400Z

thanks! I will check them out

seancorfield 2021-05-26T23:19:44.474100Z

That hasn’t been updated in three years and a lot has changed in the ClojureScript world. Shadow_cljs and Figwheel Main are the two dominant cljs solutions these days I think?

seancorfield 2021-05-26T23:21:18.474300Z

(also Boot is not very widely used and I don’t think it’s getting much maintenance these days — I opened an important issue on boot-clj/boot-new months ago and have had zero response, even with repeated nudges).

max minoS 2021-05-26T23:22:47.474500Z

that's really unfortunate, do you have any other resources that might be well suited for me to learn web development using ClojureScript? I have poked at shadow-cljs a little to make a todo-list with reagent but didn't get very far and got a little confused when I tried to add on to it