Fork me on GitHub
#beginners
<
2020-01-03
>
johnjelinek00:01:50

why does it need to be replaced with reduce? seems to be working

hiredman00:01:20

if the return values of the builder methods matter

hiredman00:01:47

which, depend on the builder sometimes it matters, sometimes it doesn't

seancorfield00:01:12

c.j.d. is very focused on beans. I'd have to do something else to work with builder classes. Still, I have the JIRA issue now 🙂

👍 1
jon00:01:06

Will this be me if I learn a LISP? Please be honest.

jon00:01:23

But seriously, I am looking for book suggestions.

alexmiller00:01:06

Only if you do it right! ;)

hiredman00:01:48

sicp is a lisp book, but it is using lisp to understand foundational computer science stuff, so it is great, but not really an intro to clojure kind of thing

alexmiller00:01:31

Learning Scheme/Lisp is a good side effect of reading SICP but not really the point :)

hiredman00:01:19

https://www.amazon.com/ideas/amzn1.account.AFAABBRGIVOWVKTHP5NOJU5LMROQ/3BSKWCYM12RBZ (links to the 1st edition of programming clojure, but the 3rd edition is current)

alexmiller00:01:40

If your goal is to learn Clojure, I’d recommend Clojure for the Brave and the True, Getting Clojure, Living Clojure, and Programming Clojure as good starters

Alper Cugun08:01:01

All four? I read Brave, what should I read next?

Nate Sutton00:01:17

getting clojure++

Vachi01:01:23

Hi everyone, I have a web application that downloads .jpg images and stores under /resource/public/img folder , everything works fine when running in dev, I want to deploy with a uberjar , but the images are not stored under /resource/public/img anymore, since is a .jar, it seems that the resource folder can't be updated?. I tried to wrap-resources to another folder, but it keeps serving from /resource/public/img , any idea on why is that?

noisesmith01:01:40

a resource is optionally from inside a jar, or on disk

noisesmith01:01:57

if you want the running app to store on disk, you probably don't want resources, but rather files

noisesmith01:01:35

and you'd have a task at deploy or app startup to make sure the directory structure is ready for usage (and likely configure its location)

Vachi01:01:10

yeah I tried that, but it keeps serving the static files from /resource/public/ from the .jar

(defn wrap-base [handler]
  (-> ((:middleware defaults) handler)
      (wrap-defaults
        (-> site-defaults
            (assoc-in [:security :anti-forgery] false)
          (assoc-in [:static :resources] "/var/www/public/")
            (assoc-in  [:session :store] (ttl-memory-store (* 60 30)))))
      wrap-internal-error)) 

noisesmith01:01:31

you need wrap-files, it's not a default

metal 1
Vachi01:01:00

with

(assoc-in [:static :files] "/var/www/public/")
it worked, many thanks!

👍 1
Vachi01:01:56

oh, will try

jon01:01:12

Does Clojure have any good GUI toolkits? I was a bit disappointed with Erlang/Elixir’s offerings, even Joe Armstrong evaluated their options and found them severely lacking. But I expect there would be more options on a JVM language.

jon01:01:34

Interesting thanks

nate01:01:09

cljfx also looks good. There's a #cljfx channel for it.

didibus02:01:14

Those are the two most popular ones I believe. You can also interop with the Java toolkits directly, those above two are wrappers for some of them. And some people go for ClojureScript for GUIs instead, building over Electron, etc.

jon02:01:03

I’m a little confused why the Clojure GUI toolkits don’t have websites with all the GUI elements layed out. I also went to the official JavaFX website and it’s hard to find screenshots of the GUI in action. Seems like a lost opportunity for adoption when it’s all so abstract.

jon02:01:15

I’ve noticed the same thing in Ruby and Erlang, or any cross-platform GUIs. Maybe just not enough momentum for that yet.

didibus02:01:35

I mean, Swing is like 20 years old 😛

didibus02:01:43

I'm not sure momentum is what they're lacking

1
didibus02:01:06

I think its because most of the time, the toolkits have really ugly default styling

didibus02:01:15

And if you want nice styling, there's commercial offering

jon03:01:56

Makes sense. I imagine it takes a lot of work to maintain a compatibility layer across the platforms that looks fully native on all. In that light I suspect I’ll still be writing Javascript/Dart for a few more years.

didibus03:01:45

Well, Java has all types of GUI toolkits. One uses native controls, one simulates native looking controls. But I'm not talking about that so much, since native look and feel of desktops are also pretty ugly

didibus03:01:18

Most real commercial app is custom styled

didibus03:01:07

This is the best I found 😛

Kamuela11:01:59

@U0K064KQV you mentioned electron-based, what’s the project there?

didibus17:01:27

There's no framework for it. You just use ClojureScript with Electron directly. A quick google found this that seems like it helps explain how to do so a bit https://github.com/martinklepsch/electron-and-clojurescript/

didibus17:01:11

There's also some lein templates apparently

didibus17:01:42

Though they look a bit old

deep-symmetry23:01:03

Seesaw was a nice way to get started quickly building a GUI app in Clojure, and was able to take me pretty far: https://github.com/Deep-Symmetry/beat-link-trigger#beat-link-trigger But it has some quirky non-idiomatic aspects, some of the documentation is confusing, and it is not being actively maintained. Today, being much stronger at both Clojure and Java Interop, I would probably just code directly to the underlying Swing API.

deep-symmetry23:01:12

I ended up using Radiance Substance as a custom look and feel, which fit in well with the music/performance application aesthetic. https://github.com/kirill-grouchnikov/radiance#radiance-libraries

didibus00:01:20

Couldn't you extend Seesaw to what's missing?

didibus00:01:16

Oh, cool app

deep-symmetry18:01:16

Thanks! The problem is that I would want to take some things away while extending others, so it would not be fair to still call it seesaw. And I am way too busy adding features that people are actually asking for to spend my free-time coding budget on a bike-shedding rewrite like that. 😄

didibus18:01:39

Totally fair. I think I'm more curious about, having used Seesaw and swing a lot to make an app like that. Do you even see value in something like Seesaw over direct use of Swing? Like given you had time and money to extend Seesaw to your liking, would you even? Or is direct usage of Swing just simpler in the end?

deep-symmetry19:01:01

There’s definitely value in Seesaw, and for getting started it’s faster and easier than learning all the Swing details and tedious Java interop variations. I don’t regret using it, and probably wouldn’t have even started the proof of concept that became Beat Link Trigger without Seesaw to smooth the initial development. The parts I somewhat regret are being tied to it now, given that it probably won’t ever get updated to run cleanly in JDK 11 (due to some reflection on internal classes that violate the new module boundaries) and that it also encouraged me to use MigLayout, a powerful layout manager that it provides a wrapper for, which is also a one-person project that seems to be abandoned, and I worry that the rest of the documentation may go offline any day, as some sites including the support forums already have. http://www.miglayout.com

deep-symmetry19:01:37

A project to update and clean up Seesaw would be wonderful, and perhaps another to write a nice layout manager in idiomatic Clojure would be wonderful things. It would not surprise me if the Seesaw author would be supportive of such efforts.

deep-symmetry19:01:48

Part of the reason things are a little in limbo at the moment, I believe, is due to the overall confusion and aborted projects in the entire Java desktop/GUI ecosystem. A whole lot of energy was lost when so much of the developer community moved to mobile and web applications, reducing the mind-share of desktop apps in a big way, and torpedoing Java’s “write once, run anywhere” dream. Then, Sun and Oracle invested a huge amount of energy into JavaFX as a supposed replacement for Swing, only to abandon that completely a year or two ago and completely removing it from the platform today.

didibus00:01:25

Ya I know, the landscape is a bit weird. Gluon seems to be taking good care of JavaFX for now, but I feel like in a weird way, Swing was pretty solid, and maybe Java should have just double downed on it.

didibus00:01:56

Anyways, thanks the for insight. It's a really cool app you have, with a nice looking GUI I would say.

jon02:01:35

With its simple syntax, wouldnt that make LISP compilers/interpreters extremely fast?

didibus03:01:05

What do you mean? In general Lisps are pretty damn fast to both compile or be interpreted (though most Lisps are compiled and not interpreted)

didibus03:01:45

But also compilation is very incremental, because the unit is a form, not a file.

codeGlaze02:01:12

Hey all, a few other people and I jumped feet first into a ... rather dense existing project. The original creator set up a bunch of custom ... entities that IDEs are having trouble following. Both intelliJ and VS Code cannot follow their custom functions prepended with question marks. Which are... heavily used in the project. Any advice on helping configure the IDEs to parse them properly? Or any questions you might be able to shoot my way to help describe this better would be appreciated too. 🙂

didibus03:01:43

Hum, entities arn't really a Clojure thing. Do you mean functions?

pez08:01:32

Please ask in #calva-dev too. I'll be afk a while and this question will be swallowed up here when I am back, I think.

jon03:01:49

Does ClosureScript run on Node?

Nate Sutton03:01:13

for sure, lumo is nice

Nate Sutton03:01:23

there's also planck

dharrigan10:01:28

Why does this work when destructuring and renaming at the same time?

dharrigan10:01:56

(let [{wibble :foo} {:foo "bar}] (println wibble))

andy.fingerhut11:01:01

Are you asking why it is allowed to assign the destructured value of a key :foo to a name that has no similarity to :foo , like wibble ?

andy.fingerhut11:01:46

In general, programming languages often let you use whatever names you wish for local variables and function parameters, and this is another example of that.

dharrigan11:01:57

I should have made myself clearer. What is special with this Clojurism that allows the binding {wibble :foo} to take the :foo keyword and put the value of "bar" into wibble. I'm just unsure of the way it works, it looks like the binding is creating a new map, with wibble as the key and being assigned the value that :foo has from the other map {:foo "bar"}. Yet, with let (and bindings), it's like this if [wibble (function etc..)] where wibble will be assigned the evaluation of the function call

dharrigan11:01:11

It just looks a bit strange and I'm trying to understand why the lefthand side looks like a map

dharrigan11:01:30

yet it's treated like destructuring into a var called wibble

dharrigan11:01:16

(bit like [{:keys [foo]} {:foo "bar"}], but you can't rename foo to another name, i.e., wibble, you have to use the form as shown above.

dharrigan11:01:19

Does that help?

markmarkmark13:01:20

@dharrigan that's just what associative destructuring looks like. consider

(let [{wibble 1 wobble 0} [:foo :bar]] (println wobble wibble))

markmarkmark13:01:32

basically, just how a let binding looks like [binding-name expression] an associative destructuring binding looks like {binding-name key}. {:keys [foo]} is just a shorthand for {foo :foo}

dharrigan13:01:59

I see I see. I'm trying to understand the shape of the stucture and that helps a lot to explain it

markmarkmark13:01:27

yeah, I always forget how associative destructuring works. I've had this aha moment at least 15 times 😛

dharrigan13:01:30

so, that shape is for associative destructuring.

dharrigan13:01:55

I use the {:keys [...]} shorthand a lot

dharrigan13:01:25

but there are times I need to rename the var, and thus do the {wibble ...} way, and I was trying to understand why that works

noisesmith19:01:46

a rationale for the syntax working that way: you can only have a given key once in a hashmap, and you can only have a binding visible with one value in a scope

noisesmith19:01:02

so there's a natural symmetry there from keys to binding names

noisesmith19:01:32

this also means you can have multiple bindings that use the same keys - sometimes this is even useful I bet

noisesmith19:01:37

also, if the values were on the key side and the bindings on the val side, a destructure would be "mirror image" in a weird way - with any nested structure all happening in the keys, and the vals all being symbols

dharrigan19:01:57

thank you for that information 🙂

dharrigan13:01:43

and it works, simply because that's the form when doing associative destructuring.

teslanick15:01:22

I’ve started noodling with Clojure for a while after a long absence. I want to break a string into individual characters, while supporting surrogate-pair characters. I have a solution that mostly works, I’m wondering if there’s something easier that I’m not seeing

teslanick18:01:39

Using iterator-seq and .codePoints is much better.

noisesmith19:01:31

I don't think there's ever a reason to use .toString instead of str in clojure code, btw

👍 1
teslanick15:01:12

(Apologies for possibly terribly-formatted code.)

alexmiller15:01:33

there is a String.codePoints() method that is surrogate-aware - not sure if that's helpful?

teslanick15:01:12

I’ll take a look at that, thanks!

Eamonn Sullivan15:01:56

Hi all, I have a fairly large (probably too large, for a first real clj/cljs project) project that I generated with the lumninus template and a fair number of options (+re-frame +graphql +postgres +shadow-cljs). I'm working through the project slowly as a way of learning the language and the build tools. Is it worth me trying to convert this to cli/deps project instead of a leiningen one? I have a list as long as my arm of things I still don't know how to do and I'm not sure where to prioritise the CLI tools. Is it difficult to convert a leiningen project? Or are there things that Leiningen is giving me that just aren't available yet?

alexmiller15:01:52

I wouldn't bother spending time on that. you're likely to run into things that you can do with lein but can't as easily do with clj yet

alexmiller15:01:37

Using lein is perfectly fine - I'd stick with that if it's working for you

Eamonn Sullivan15:01:47

Thanks. It has moved to the bottom of the list. I suspect the project I'm trying is big enough that it might be worth spinning off a library or two. When I get that sophisticated, I'll try to do those libs as a deps.edn project.

teslanick17:01:13

To my previous question—my head hasn’t been in Java in forever, it looks like Java streams implement Iterator, so it should be easy to interact with them in Clojure, but I’m uncertain about how.

alexmiller17:01:27

iterator-seq

ghadi17:01:40

they do not implement Iterator, but you can ask them for an iterator with (.iterator the-stream), and they do not implement Iterable 🙂

teslanick17:01:28

Sorry, yeah. I’m in JS-world where “implements iterator” means something somewhat different and I was thinking about it in that way.

teslanick17:01:38

(“implements iterator” in JS means it has a property [Symbol.iterator] that’s a function that returns an iterator object)

ghadi17:01:45

ah yeah I forget how easy it is in js

teslanick17:01:33

Yeah. The thing I want to do in JS is as simple as […stringWithEmoji] 😛

ghadi17:01:44

Iterator means you have a pair of methods hasNext() and next(0 Iterable means you have a method iterator() Streams have a method iterator() but do not implement Iterable

ghadi17:01:58

which is surprising

teslanick17:01:17

That… is surprising

Gulli17:01:06

That is really weird. I'm sure there is a reason for that

FiVo18:01:52

Does somebody know how to use pomegranate with a standalone jar?

FiVo18:01:58

Getting:

FiVo18:01:03

Exception in thread "main" java.lang.IllegalStateException: Could not find a suitable classloader to modify from clojure.lang.LazySeq

FiVo18:01:21

The README says something about about "a situation where you are using pomegranate but do not have a clojure.lang.DynamicClassLoader visible in your classloader hierarchy, you will need to explicitly enable the .URLClassLoader support in dynapath (upon which pomegranate relies for such things" but I don't know how to add the support via dynapath.

seancorfield18:01:02

(let [cl (.getContextClassLoader (Thread/currentThread))]
    (.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl)))
@finn.volkel Add that near the top of your -main function.

👍 1
seancorfield18:01:07

(it's what Clojure's REPL does and it's what we do in our dev/repl.clj file at work to ensure a DCL context for starting Cognitect's REBL so we can use the add-lib branch of t.d.a. and add new dependencies on the fly without restarting REBL)

FiVo18:01:15

Thank you that worked.

FiVo18:01:10

What is the status on the add-lib branch? Is that going into tools.deps.alpha anytime soon and if so will it support leinigen or should I rather not bet on that?

seancorfield19:01:36

Still to be decided, according to the latest from Alex. No idea what you mean about "will it support leiningen"?

alexmiller20:01:16

it is actually designed such that you can inject the initial dep context so it could be used from things other than clj, possibly including leiningen

alexmiller20:01:50

the plan is to integrate it into tools.deps but it needs some modifications

FiVo19:01:46

@U064X3EF3 Currently playing around with the add-libbranch. The following doesn't work

(deps/resolve-deps
 '{:deps
   {next.jdbc {:git/url ""
               :sha "425d1c367c2e7c585cb85b1b379cf5a3a1c49792"}}}
 nil)
I have to do:
(require '[clojure.tools.deps.alpha.util.maven :as mvn])
(deps/resolve-deps {:deps {'org.clojure/java.data {:mvn/version "0.1.5"}}
                    :mvn/repos mvn/standard-repos} nil)
(deps/resolve-deps
 '{:deps
   {next.jdbc {:git/url ""
               :sha "425d1c367c2e7c585cb85b1b379cf5a3a1c49792"}}}
 nil)

FiVo20:01:58

Thanks had not seen that.

FiVo20:01:37

@seancorfield But still getting some issues in some cases:

(add-lib 'org.clojure/tools.trace {:mvn/version "0.7.10" }) ;; works
  (load-master 'clojure/tools.trace) ;; doesnt
  (add-lib 'org.clojure/data.json {:mvn/version "0.2.7" }) ;; works
  (load-master 'clojure/data.json) ;; works

seancorfield20:01:25

@finn.volkel tools.trace doesn't have deps.edn so you can't pull that in with the CLI/`deps.edn` stuff.

seancorfield20:01:38

i.e., with load-master from GitHub.

seancorfield20:01:29

(it does have a pom.xml file tho' so I would have expected that to work...)

seancorfield20:01:21

Hmm, it works just fine for me:

user=> (require '[clojure.tools.deps.alpha.repl :refer [add-lib]])
nil
user=> (require '[clojure.tools.gitlibs :as gitlibs])
nil
user=> (defn load-master [lib]
(let [git (str "" lib ".git")]
(add-lib lib {:git/url git :sha (gitlibs/resolve git "master")})))
#'user/load-master
user=> (load-master 'clojure/tools.trace)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.
Checking out:  at e6bc29e4c1d9d69d6d9d7cce62ee8da02662d284
true
user=> (require '[clojure.tools.trace :as t])
nil
user=> (t/trace (* 2 3))
TRACE: 6
6

seancorfield20:01:36

@finn.volkel When you say "doesnt" work -- could you be a bit more specific about what isn't working and how it is failing for you?

FiVo21:01:49

@seancorfield

1. Unhandled java.lang.NoSuchMethodException
   org.apache.maven.repository.internal.DefaultModelResolver.<init>(org.eclipse.aether.RepositorySystemSession,
   org.eclipse.aether.RequestTrace, java.lang.String,
   org.eclipse.aether.impl.ArtifactResolver,
   org.eclipse.aether.impl.VersionRangeResolver,
   org.eclipse.aether.impl.RemoteRepositoryManager, java.util.List)

FiVo21:01:26

Sorry I hadn't realized that I have clojure/tools.trace already as dependency in my project. So might be that.

FiVo22:01:18

Yes tested it in a clean project and it worked.

FiVo22:01:09

Added the dependencies to project.cljof the clean project but still not getting the error there.

FiVo22:01:46

Ok it's some dependency issue.

FiVo22:01:46

Here are the dependencies of the project.clj where it fails.

:dependencies [[cheshire "5.9.0"]
                 [clj-http "3.10.0"]
                 [clj-jgit "1.0.0-beta2"]
                 [com.cemerick/pomegranate "1.1.0"]
                 [org.clojure/clojure "1.10.0"]
                 [org.clojure/core.match "0.3.0"]                 
                 [org.clojure/math.combinatorics "0.1.6"]
                 [org.clojure/tools.gitlibs "0.2.64"]
                 [org.clojure/tools.analyzer.jvm "0.7.2"]
                 [org.clojure/tools.namespace "0.3.1"]
                 [org.clojure/tools.trace "0.7.10"]
                 [org.clojure/tools.cli "0.4.2"]
                 [org.tcrawley/dynapath "1.1.0"]
                 ;; [tentacles "0.5.1"]
                 [com.github.clojure/tools.deps.alpha "add-lib-SNAPSHOT"]]
  :repositories [["jitpack" ""]] 

FiVo22:01:11

These also break it in a clean project.

seancorfield22:01:10

I didn't think t.d.a.'s add-lib branch was available except via a git dependency.

seancorfield22:01:59

I wouldn't expect you to need pomegranate, clj-jgit, tools.gitlibs, or dynapath if you're pulling in t.d.a. -- but any of those could be breaking add-lib.

seancorfield22:01:25

I've no idea how you would do this with Leiningen tho' -- I haven't used it for years.

FiVo22:01:55

But it's a git dependency. Maybe I didn't understand you correctly.

FiVo22:01:36

I essentially want to mine some clojure code that's why I am experimenting with pomegranate and the clojars api. The other option was to use the add-lib branch and tentacles (github api interface). The git approach would probably give me more code but currently all leiningen projects would not be loadable, that's why I asked.

FiVo22:01:44

Do you think one option is better suited/rebust then the other?

seancorfield22:01:54

I've no idea. I only use add-lib via CLI/`deps.edn` and it just works the way I showed. It can load projects via git that have pom.xml or deps.edn files. It can load projects via regular coordinates from Clojars and Central. I was just trying to help you with it because you were saying things "didn't work" but you didn't explain how they weren't working.

seancorfield22:01:52

I don't know what you mean by "mine some clojure code" and you didn't state what problem you were trying to solve.

alexmiller22:01:56

pomegranate and some other things there use different version of the maven resolver etc - it's highly likely that you can end up with a set of maven transitive dependencies that won't work with tools.deps

alexmiller22:01:08

I'd say it's almost certain that's the explanation for the exception you posted earlier (and this may be non-deterministic - moving deps around in project.clj could affect whether you see it)

seancorfield22:01:20

Yeah, that was what I was suggesting a quarter-hour ago: the dependencies listed in your project.clj are probably breaking t.d.a.

alexmiller22:01:39

yes, I'm confirming that :)

seancorfield22:01:04

Oh, I missed the exception in all the back and forth. I think that came in round about when I switched computers...

alexmiller22:01:17

re "The other option was to use the add-lib branch and tentacles (github api interface)." - I don't know how that would work

FiVo22:01:41

ok maybe I should explain what I want to do

alexmiller22:01:58

well, that's usually a good place to start :)

seancorfield22:01:59

Starting with a problem statement is often very helpful 🙂

FiVo22:01:18

I want to use tools.analyzer.jvm on lots of source code, essentially retrieving information on the AST's paths. Currently I use the clojars api (https://github.com/clojars/clojars-web/wiki/Data) to get information on the artifacts I am interested in and the version. Afterwards I load the dependencies via pomeranate. Then find all the namespaces via ns-find/find-namespaces-in-jarfile and then analyze the namespaces via analyze-ns to get the AST's.

FiVo22:01:41

It currently feels like a bit hack. I would love to do it more cleanly

FiVo22:01:17

The add-lib + github api approach feels cleaner as I have immediatly the information on what is a fork and what not. I can also sort projects on number of stars to get higher quality code etc..

FiVo22:01:48

The endgoal is to do ML on Clojure Code. If you think there is also a completely different approach to doing things I more then happy to hear it.

FiVo22:01:26

s/bit hack/big hack/

alexmiller22:01:04

tools.deps can download the git libs for you, so you don't technically need tentacles at all btw

alexmiller22:01:54

well, I guess maybe you're using it for other stuff

alexmiller23:01:45

it all seems reasonable to me - but I would just pick one path and kill the deps for the other one to avoid conflict between them

FiVo23:01:56

tentacles was more for the meta information of the repositories and also finding repositories, I agree I don't need to actually load the deps

FiVo23:01:25

totally agree with the one path approach, I was just not sure in which state the add-lib branch is and what it will support in the end.

alexmiller23:01:55

the tip of add-lib branch had master merged into it recently, so it's basically additive to the main line

alexmiller23:01:23

I do not have any guarantee or expectation for you on when it will be more officially available

FiVo23:01:39

ok thanks anyway

alexmiller23:01:02

to be useful, it's api will be approximately what it is now (since there's not much to it)

FiVo17:01:47

@U064X3EF3 @seancorfield Sorry to bother once more. So I think there is some issue with the add-lib branch and leiningen. I essentially followed the instructions from your post (https://insideclojure.org/2018/05/04/add-lib/) and it works fine on clj. If I do the same thing in a clean leinigen project that has only clojure and the add-libbranch as dependencies I get an error for the following

(ns foo.core
  (:require [clojure.tools.deps.alpha.util.maven :as mvn]
            [clojure.tools.deps.alpha.repl :refer [add-lib]])
  (:gen-class))

(add-lib 'org.clojure/tools.trace {:mvn/version "0.7.10" })
(require 'clojure.tools.trace)
The error I get when requiring is:
1. Unhandled .FileNotFoundException
   Could not locate clojure/tools/trace__init.class,
   clojure/tools/trace.clj or clojure/tools/trace.cljc on classpath.
It might have to do with the fact the leinigen depends on pomegranate and that might clobber the classpath somehow.

alexmiller17:01:52

You shouldn’t have pomegranate on the repl classpath in lein afaik

FiVo17:01:04

Yes it's not the classpath.

alexmiller17:01:01

What does the call to add-lib return?

alexmiller17:01:42

It returns the things it added

FiVo17:01:33

It returns ture I wanted to say.

FiVo17:01:13

So there is some version of dynapath loaded via cider.

FiVo17:01:33

#namespace[cider.nrepl.inlined-deps.dynapath.v1v0v0.dynapath.util] don't know if that is the issue

alexmiller17:01:55

add-lib is designed to work with clj

FiVo17:01:17

Sure. I understand that it is work to make it work for every tool out there. Maybe I dive into the problem.

johnjelinek18:01:55

Is it possible to point to a Java github project with deps.edn and have it build so it can be used in the clojure project?

johnjelinek18:01:28

I put in the sha to my deps.edn and it's acting like the library isn't in the classpath

alexmiller20:01:30

deps.edn / clj are designed only for source-only Clojure projects and do not include any "build" step

ghadi18:01:58

no because Java things require a build step

johnjelinek18:01:53

where does deps.edn clone to so I can build it manually?

seancorfield18:01:02

~/.gitlibs is where Git checkouts end up.

johnjelinek18:01:29

ok -- so, if I mvn package successfully in the ~/.gitlibs path -- can I then reference it and it'll show up in the classpath, or do I need to drop a jar in somewhere else?

andy.fingerhut19:01:04

mvn install puts a JAR in appropriate directory in your ~/.m2 directory, where they can be found by almost any tool I know about that looks for JAR files.

andy.fingerhut19:01:34

But off hand I do not know what happens if you were to take a project that was Clojure source only, create a JAR in /.m2, and then try to use deps.edn to use it -- might be some additional details about how you do it to decide whether it uses /.gitlibs or ~/.m2 version then.

seancorfield19:01:24

If it has pom.xml etc, it works just fine, because it looks like a regular (maven) artifact and you can depend on it by group/artifact/version.

seancorfield19:01:55

So it really depends on how "packagable" the Clojure project is...

seancorfield18:01:20

You can sort of use the CLI to compile Java code via an appropriate -e option that shells out and runs javac but it's pretty nasty and likely only works in the simplest of setups...

seancorfield18:01:22

...some variant of this:

clojure -e "(require '[clojure.java.shell :refer [sh]])(sh \"javac\" \"Hello.java\")(shutdown-agents)"

johnjelinek18:01:53

I did a mvn package in the .gitlibs path and it dropped a jar in target -- do I need to move this anywhere for clojure to pick it up?

alexmiller19:01:20

You should not modify the stuff under .gitlibs

johnjelinek18:01:34

well, it didn't seem to pick up in the classpath, so I guess it needs to be moved somewhere

seancorfield18:01:39

It needs to be on the classpath -- if you do a local mvn install it'll go into ~/.m2/repository and then you can depend on it by group/artifact/version.

seancorfield18:01:49

Given the path into the project under .gitlibs changes with each SHA, you might be better off manually cloning the repo somewhere stable and adding the appropriate directory as a dependency via :local/root...

seancorfield19:01:01

...depends on how reproducible you want that to be.

mruzekw19:01:54

Can I create and pass around middleware chains and connect them to a handler later?

mruzekw19:01:41

Assuming a typical ring middleware

mruzekw19:01:00

This closest to that I can come up with is:

(defn chain [handler]
  (-> handler
      (m/wrap-content-type "application/transit+json")))

seancorfield19:01:47

@mruzekw Yes, middleware is just functions, and composing two middleware functions produces a new middleware function.

mruzekw19:01:08

So I could just use comp as well?

mruzekw19:01:10

Hmm, how would that work with a middleware that takes the handler first?

seancorfield19:01:50

#(m/wrap... % "my" "args") for each middleware

mruzekw19:01:14

So manual thread-first in a way

seancorfield19:01:15

I think -> threading is easier to read tho'.

mruzekw19:01:44

So you would do something like (defn chain [handler]…?

mruzekw19:01:21

Or is there some comp + -> I’m not seeing?

seancorfield19:01:45

(defn wrapper
  "Given the application configuration, return middleware that has all the
  things we need configured."
  [config handler]
  (-> handler
      (add-config config)
      (sanitize-parameters)
      (ring-json/wrap-json-response (:json-config config))
      (ring-defaults/wrap-defaults
       (-> ring-defaults/site-defaults
           (as-> % (merge-with merge % (:ring-defaults config)))
           ...))
      (wrap-client-ip)
      (ring-json/wrap-json-params)
      (cors)))

seancorfield19:01:24

You can use just comp for middleware that only takes the handler...

seancorfield19:01:45

(but be careful trying to mix -> and comp!)

mruzekw19:01:08

haha I’ll probably stick closer to the example you just posted

mruzekw19:01:31

Thank you!

mruzekw19:01:36

@seancorfield Could I also do something like?

(def chain '[(myapp.backend.middleware/wrap-content-type "application/transit+json")
             (myapp.backend.middleware/wrap... {:param1 "val1"})])

(apply -> handler chain)

seancorfield19:01:40

You can't apply a macro. -> is purely a syntactic transformation.

seancorfield19:01:30

If you want to represent the chain of middleware as "data" you could make them all single argument anonymous functions and then apply comp on that

seancorfield19:01:03

(def chain [#(myapp.backend.middleware/wrap-content-type % "application/transit+json")
            #(myapp.backend.middleware/wrap... % {:param1 "val1"})])

(apply comp chain)

mruzekw20:01:56

Okay, thanks