Fork me on GitHub
#beginners
<
2022-04-06
>
vlad_poh12:04:18

Hi is it possible to create namespaced string keys and if so how?

dgb2312:04:33

Not really - but you can convert keywords to strings and vice versa if that helps.

vlad_poh12:04:09

there are spaces in some of the string keys and i don't want to change the keys

emccue15:04:21

{:namespace "what is this"
 :name "eeey"}

emccue15:04:01

if it doesn't cleanly fit into a keyword, symbol, or string - you can always use your own aggregate as a key

emccue15:04:45

i wouldn't call this the most idiomatic thing in the world - but keywords and symbols are more for programatic identifiers and it sounds like your thing comes from outside data

emccue15:04:14

and to be clear

{{:namespace "what is this"
  :name "eeey"}              123}
Using maps as keys does work

✔️ 1
mister_m15:04:33

I've got a list of urls I need to do some processing on: basically initiate a GET and do some processing on the response, and finally serializing $stuff to sqlite. How do I want to do this in clojure? Should I map the list into a series of future objects that I then wait on? Should I investigate core.async for something like this?

emccue15:04:47

i'd say neither

emccue15:04:15

futures are backed by a "cached thread pool", so if you kick off a bunch of get requests all at once you will get exactly that many threads

emccue15:04:05

which may or may not be okay, but i would use https://github.com/clj-commons/claypoole with your own executor

emccue15:04:30

OR, just run all the requests in order without any async and see if its fast enough

popeye17:04:10

I was looking into the repo https://github.com/nberger/ring-logger , can we also add response data in the log ?

oddsor18:04:13

Might not be understanding the question, but this seems to be what the wrap-log-response-function is for 😊

popeye18:04:43

@UDB2Q0W13, I meant if my api is returning {:a "message"} does we get the response in the logs?

oddsor20:04:33

Aha, I looked at the source code and it looks like only the response status gets logged 😢

fadrian18:04:51

I'm trying to use a 3'rd-party .jar file in a deps.edn project. I've put the jar file in a folder local to my project and pointed to it in the :deps section of my deps.edn file using a :local/root directive as shown in the "Include a local jar on disk" section of the "Deps and CLI Guide" document. However, I'm getting an error:

Error building classpath. Manifest type not detected when finding deps for <library> in coordinate #:local{:root <path-to-jar>}
Why is this error being thrown and what do I do about it? The "Deps and CLI Guide" doesn't mention anything about a manifest in the section on including the jar file.

Alan Birchenough18:04:08

Doesn’t the jar file itself need to contain a manifest? (See https://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html).

Alan Birchenough18:04:12

Are you sure that it does?

hiredman18:04:40

Manifest in this case refers to a deps.edn or pom.xml file in the jar

hiredman18:04:15

Which is confusing because jars also can a manifest file which is something else entirely

hiredman18:04:01

What version of the cli tools are you using?

hiredman18:04:05

I don't entirely recall under what circumstances tools.deps requires a pom or dep.edn file, but I would not expect it to require one in that case

seancorfield19:04:12

Is that 3rd party JAR file publicly accessible so we can double-check what is in it? And, yes, what does clojure -version say, and perhaps also share your whole deps.edn file if you can. More information will make it easier for us to help you @U0DTU8J83

Alex Miller (Clojure team)19:04:29

I suspect the error means no pom.xml was found in the jar file (which is used for finding transitive deps)

Alex Miller (Clojure team)19:04:43

possibly that is required when it should not be

Alex Miller (Clojure team)19:04:45

I'm a little curious if that is the actual error as that implies you actually have "path-to-jar" in your deps (not sure if that was a concealing edit)

Alex Miller (Clojure team)19:04:24

yeah, this doesn't seem to be an issue

% jar cf foo.jar README.md
% clj -Sdeps '{:deps {foo/bar {:local/root "foo.jar"}}}' -Stree
org.clojure/clojure 1.11.1
  . org.clojure/spec.alpha 0.3.218
  . org.clojure/core.specs.alpha 0.2.62
foo/bar /Users/alex.miller/code/foo.jar

Alex Miller (Clojure team)19:04:32

seems fine to not have a pom.xml in the jar

dpsutton20:04:29

An issue i’ve had in the past doing this is i would put the path to the folder containing the jar rather than the path to the jar itself. ie /Users/dan/stuff/ instead of /Users/dan/stuff/library.jar. If that’s perhaps your issue

Alex Miller (Clojure team)20:04:21

the error at the top implies the actual deps.edn has "<path-to-jar>" in it (that's not in any error message)

dpsutton20:04:26

I think its consistent with i’ve written here:

clj -Sdeps '{:deps {metabase/metabase {:local/root "/Users/dan/projects/work/jars"}}}'
Error building classpath. Manifest type not detected when finding deps for metabase/metabase in coordinate #:local{:root "/Users/dan/projects/work/jars"}
If you put a path to a jar and forget to include the jar name you receive exactly that error. I have 10 jars in that directory but i’ve done this in the past when i downloaded a jar and wrongly thought i had to point at the folder containing the jar rather than the jar itself

Alex Miller (Clojure team)20:04:02

agreed and that is common, but I don't think that's the issue here

Alex Miller (Clojure team)20:04:27

but until the OP clarifies, can't tell

fadrian21:04:22

Sorry it's taken a while to get back to you. Here's my deps.edn:

{:paths
 ["src"]

 :deps
 {org.clojure/clojure {:mvn/version "1.10.3"}
  compojure/compojure {:mvn/version "1.6.2"}
  http-kit/http-kit {:mvn/version "2.5.3"}
  ring/ring-json {:mvn/version "0.5.1"}
  ring-cors/ring-cors {:mvn/version "0.1.13"}
  org.clojure/data.json {:mvn/version "2.4.0"}
  mercator/mapper {:local/root "../mercator"}
  mercator/expander {:local/root "../mercator"}
  mercator/primitives {:local/root "../mercator"}
  mercator/templates {:local/root "../mercator"}
  cheshire/cheshire {:mvn/version "5.0.2"}
  ;; The one below is the one that's giving me an issue...
  apelon-dts/dtscore {:local/root "resources/jars/apelon"}}

 :jvm-opts ["-XX:-OmitStackTraceInFastThrow"]
 
  :aliases {;; build an uberjar (application) with AOT compilation by default:
            :dev {}
            
            :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
                      :exec-fn hf.depstar/uberjar
                      :exec-args {:aot true}}
  ;; build a jar (library):
            :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
                  :exec-fn hf.depstar/jar
                  :exec-args {}}}}

dpsutton21:04:43

{:local/root "resources/jars/apelon"} doesn’t seem to be a path to a jar but a path to a folder that may or may not contain a jar?

fadrian21:04:27

The jar file has a pom.xml in its maven directory and has a MANIFEST.MF file in the META-INF directory.

fadrian21:04:42

It is the name of the directory that has the .jar file in it.

fadrian21:04:10

Should I be adding the name of the .jar file, as well? Trailing /?

fadrian21:04:59

The full error message I'm getting is:

Error building classpath. Manifest type not detected when finding deps for apelon-dts/dtscore in coordinate #:local{:root "C:\\Users\\fadrian\\Projects\\motive-cql-builder\\mercator-server\\resources\\jars\\apelon"}

dpsutton21:04:17

yes use a full path to the jar.

fadrian21:04:46

OK. I've changed my :deps declaration for the .jar file to:

apelon-dts/dtscore {:local/root "resources/jars/apelon/dtscore-4.6.1-838.jar"}
I'm now getting the (slightly different) error message:
Error building classpath. Manifest type not detected when finding deps for apelon-dts/dtscore in coordinate #:local{:root "C:\\Users\\fadrian\\Projects\\motive-cql-builder\\mercator-server\\resources\\jars\\apelon\\dtscore-4.6.1-838.jar"}

fadrian21:04:17

The pom.xml file (to my limited experience) looks good and the groupId and artifactId all seem to match.

seancorfield21:04:35

@U0DTU8J83 And is that full path correct? That's the correct path to that .jar file?

fadrian21:04:59

Yes. The full path is correct. When going over the pom.xml files, there are some dependencies that are not in my :deps section. Would I need to add those?

Alex Miller (Clojure team)21:04:43

What version of the Clojure CLI? clj --version

Alex Miller (Clojure team)21:04:46

and inside the jar file, where is the pom? jar tf dtscore-4.6.1-838.jar | grep pom is what I would do in *nix, not sure if you're on windows

dpsutton21:04:52

I’ve tried to register 30 times at to download their jar but cannot get it to accept a password through its verification 😞

Alex Miller (Clojure team)21:04:57

it's going to look for something under META-INF/ that ends in pom.xml

fadrian21:04:20

Not certain about the version... How can I tell? pom.xml is found in META-INF/maven/apelon-dts/dtscore/pom.xml inside the .jar file.

fadrian21:04:25

1.10.3.1029

Alex Miller (Clojure team)21:04:05

can you drop me the jar file somehow?

Alex Miller (Clojure team)21:04:14

that all seems like it should be ok

fadrian21:04:59

I'm checking whether one can send the jar without running into licensing issues.

fadrian22:04:49

I've sent the .jar to you via DM.

Alex Miller (Clojure team)22:04:18

well I don't see the problem you see, but I do see others

Alex Miller (Clojure team)22:04:58

do you have anything configured in your ~/.m2/settings.xml

fadrian22:04:55

No, I don't.

Alex Miller (Clojure team)22:04:20

I can see many ways this can be problematic but not getting exactly the same errors - there are some system deps declared in the internal pom that point to hardcoded paths on your system. those fail for me, but that should be downstream from the error you're seeing, so I don't understand that. a workaround for this issue would be to instead include this as a path which will put it on the classpath without trying to understand it's deps:

{:paths ["src" "resources/jars/apelon/dtscore-4.6.1-838.jar"] 
and then remove it from :deps

Alex Miller (Clojure team)22:04:00

could also be a windows thing I guess

Alex Miller (Clojure team)22:04:25

do you have a resources/jars/apelon/project/pom.xml or something like that?

fadrian22:04:39

There is in some other jars I have from this company, but none in dtscore.

fadrian22:04:09

It turns out your suggestion of adding the file to the src paths went farther, but then crashed with an error message:

ERROR: Unhandled REPL handler exception processing message {:op eval, :code *ns*, :id 1}
<stack trace>
Caused by: java.nio.file.NoSuchFileException: c:\Users\fadrian\Projects\motive-cql-builder\mercator-server\resources\jars\apelon\dtscore-4.6.1-838.jar
<more stack trace>
This is even when I'm looking directly at the .jar file mentioned in the file manager. I'll look into more tomorrow.

Alex Miller (Clojure team)23:04:32

That looks like something failed well beyond, could tell from the stack trace

Alex Miller (Clojure team)23:04:59

Anyhow, I think something else is needed here from a feature level and I'll log something about that

fadrian23:04:05

According to the stack trace, it's throwing the exception when it's trying to read some file attributes for/within the .jar:

Caused by: java.nio.file.NoSuchFileException: c:\Users\fadrian\Projects\motive-cql-builder\mercator-server\resources\jars\apelon\dtscore-4.6.1-838.jar
        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
        at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:199)
        at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
        at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1264)
        at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:243)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:347)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:318)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:284)
        at cider.nrepl.middleware.track_state$fn__3870.invokeStatic(track_state.clj:155)
        at cider.nrepl.middleware.track_state$fn__3870.invoke(track_state.clj:155)
        at clojure.core$map$fn__5884.invoke(core.clj:2759)
        at clojure.lang.LazySeq.sval(LazySeq.java:42)
        at clojure.lang.LazySeq.seq(LazySeq.java:51)
        at clojure.lang.RT.seq(RT.java:535)
        at clojure.core$seq__5419.invokeStatic(core.clj:139)
        at clojure.core$map$fn__5884.invoke(core.clj:2750)
        at clojure.lang.LazySeq.sval(LazySeq.java:42)
        at clojure.lang.LazySeq.seq(LazySeq.java:51)
        at clojure.lang.RT.seq(RT.java:535)
        at clojure.core$seq__5419.invokeStatic(core.clj:139)
        at clojure.core$apply.invokeStatic(core.clj:662)
        at clojure.core$mapcat.invokeStatic(core.clj:2787)
        at clojure.core$mapcat.doInvoke(core.clj:2787)
        at clojure.lang.RestFn.applyTo(RestFn.java:139)
        at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3706)
        ... 68 more

seancorfield23:04:14

That is coming from CIDER/nREPL -- so you're well past the Clojure CLI and deps.edn issue. Maybe you can go ask in #cider? It might be Windows a path/escape issue in the nREPL middleware?

fadrian00:04:47

Sounds good. I'll give it a shot.

dpsutton00:04:48

(posting here as well). I'd urge you to get a repl up without any extra tooling before figuring out what is going on in CIDER and Calva. I think Calva on windows uses a reproduction of the clojure cli and not the actual cli. Further, CIDER's tooling might have a bug, or might be hitting an issue related to this jar. It was far better to get a repl using just clojure or clj command line tools and then proceed to editor integrated tooling

icemanmelting14:04:39

Why not installing the jar file locally, and then using it in the project.clj or deps directly?

mvn install:install-file –Dfile=C:\dev\app.jar -DgroupId=com.roufid.tutorials -DartifactId=example-app -Dversion=1.0

dpsutton20:04:02

A question from a coworker recently who is on the frontend (js) side and wants to learn from a good codebase: > A side topic: is this considered a good code base to learn if one wants to understand how to write a small, pure Clojure library written in idiomatic Clojure? Would appreciate if anything comes to mind

Fredy Gadotti20:04:46

I asked something like this couple weeks ago and they send a few suggestions. I like the code of https://github.com/metabase/metabase.

dpsutton20:04:32

heh. We work there and he is looking for something a bit smaller in scope that is “good code” for learning the language more than learning how to make a proper full product

😂 2
dpsutton20:04:41

(and you made our day 🙂 )

👍 1
❤️ 1
dpsutton20:04:27

that’s a pretty complex domain to jump into for someone new to the language

dpsutton20:04:31

(but an amazing project)

dpsutton20:04:44

i think something like hiccup might fit the bill?

Fredy Gadotti20:04:47

@U11BV7MTK LOL 😅 I just saw your profile now. hehe

😂 2
dpsutton21:04:50

almost too abstract. that would be handy idioms rather than library code that accomplishes something

dpsutton21:04:07

after doing Clojure for a year that library is lovely. But before some experience it would just feel like koans i suspect

dpsutton18:04:23

that is absolutely beautiful code

respatialized16:04:19

https://github.com/brandonbloom/fipp Another good choice for a small "does one thing well" library

John Bradens22:04:07

Hey I'm trying to learn how to use clj and I am trying clj -M:dev -M:repl and I'm getting

WARNING: Specified aliases are undeclared and are not being used: [:dev] 
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-M:repl (No such file or directory)
I'm new to using clj, do I need to update it or anything?

John Bradens22:04:53

Why am I getting this error & how do I fix it?

Alex Miller (Clojure team)22:04:32

everything after -M is treated as an argument passed to the main

John Bradens22:04:39

Awesome thank you! It worked