Fork me on GitHub
#clojure
<
2022-03-25
>
hlship00:03:01

Yes, moving the ^bytes to the arg vector works. Thanks!

fabrao00:03:46

Anyone had problem with Java 16 about "Implementation of JAXB-API has not been found on module path or classpath". I know that is a problem with xml binding, I tried many ways about including javax.xml.bind/jaxb-api but not that solve it. Anyone has solved it?

Alex Miller (Clojure team)01:03:04

That is how I've solved this in the past

Carlo12:03:28

When I evaluate:

(if (resolve 'foo)
  (foo :a)
  :b)
I get an error about being unable to resolve foo in this context, even if I checked that (resolve 'foo) is nil. What's the correct way of executing something if a function exists?

Noah Bogart12:03:22

Seems like a design issue. Remind of the classic stack overflow question “how do I programmatically create a variable?”, you should reconsider the design of your code to use a different data structure or change the definitions such that foo will always be defined, even if it’s an alias for identity

Ben Sless12:03:32

At the call site you also need to resolve foo. The compiler can't do it, so it won't compile it for you. You can either add a call to resolve there, or write a macro

Carlo12:03:17

Yes, good point on a different design, this snippet should work for a bit of editor integration: a clojure snippet that's called from cider so that I can use an enhanced function (`foo` ) if it's defined, or carry on if it's not. What would work here?

Carlo12:03:52

yes maybe defining foo as identity originally would work, but if you have more suggestions I'm glad to hear them

Ben Sless12:03:01

Why not use requiring resolve and if-let?

🙌 1
🎉 1
Carlo12:03:15

Thank you, if-let works!

(if-let [f (resolve 'foo1)]
  (f :a)
  :b)

Carlo13:03:31

ah, TIL about requiring-resolve, nice!

Noah Bogart13:03:18

Good call Ben, forgot about that one

Ben Sless14:03:07

:) If you find you use that pattern a lot, a macro might be in order

Carlo13:03:28

I'm a bit confused by a difference of behavior between two snippets:

(do (require '[portal.api :as p])
    (p/open)
    (add-tap #'p/submit))
vs.
(require '[portal.api :as p])
(do (p/open)
    (add-tap #'p/submit))
the first doesn't work (`p` is unknown), the second does. My naive model was that lines, even inside the do block, would have been compiled on the fly. So, does the first snippet not work because the unit of on-the-fly-compilation is a form?

ghadi13:03:23

you've come across the Gilardi Scenario™

🙌 3
ghadi13:03:00

tldr: the require form executes at runtime, not compile time

ghadi13:03:28

so in the first example p isn't a valid alias in p/open or p/submit

ghadi13:03:41

the do block is compiled all at once

Carlo13:03:47

Thank you, very instructive! So I suppose this bit from the article:

In Clojure 1.1, the compiler introduced special handling to work around this. If the top-level form being evaled is a do, then it will be broken up and each subform will be evaled separately. Unfortunately this only goes so far; it only applies to top-level dos, so even though our when above macro-expands to a form that contains do, the compiler can't apply its special-case.
applies only when I explicitly use eval and doesn't trigger in my case?

ghadi13:03:51

are you using a REPL? what type of REPL?

Carlo13:03:20

nrepl via cider-interactive-eval

ghadi13:03:22

Clojure 1.11.0-rc1
user=> (do (require '[clojure.datafy :as d]) (d/datafy 42))
42
this is in a plain old clojure.main repl, no nREPL

ghadi13:03:43

speculation: nREPL might be wrapping forms, so your top-level do isn't top-level

😍 1
Carlo13:03:09

amazing, I see what the problem could be, thanks!

Maris14:03:39

(when (bound? #'*seed-state*)
                                           *seed-state*)

Maris14:03:30

Is there a function that does this ^^^ ? Returns nil if var is unbound?

p-himik14:03:57

You pretty much wrote it yourself - it's just 2 lines. :) There's no such function in clojure.core.

Maris14:03:18

I found this:

Maris14:03:25

(defn get-possibly-unbound-var
  "Like var-get but returns nil if the var is unbound."
  {:added "1.1"}
  [v]
  (try (var-get v)
       (catch IllegalStateException e
         nil)))

Maris14:03:47

It is in clojure.test

Maris14:03:27

but it returns clojure.lang.Var$Unbound

Joshua Suskalo14:03:50

right, the purpose of this is that it fetches the value of a var that may or may not be bound.

Joshua Suskalo14:03:59

It's not designed to do what your code snippet does.

Maris14:03:03

like var-get ( it doesnt throw IllegalStateException )

winsome16:03:25

Is there a good way to get the information from clojure.repl/dir as data, instead of printed?

dpsutton16:03:54

dev=> (clojure.repl/dir-fn 'clojure.set)
(difference
 index
 intersection
 join
 map-invert
 project
 rename
 rename-keys
 select
 subset?
 superset?
 union)
dev=> (type *1)
clojure.lang.ArraySeq
dev=> 

🙏 1
dpsutton16:03:42

(source dir) shows it should be relatively simple to amend to your needs

crinklywrappr21:03:37

hey guys quick question - if i include deps.edn in jar files published to clojars, will clj read it to download dependencies which are missing from pom.xml?

seancorfield21:03:09

For dependencies brought in via :mvn/version, the pom.xml file in the JAR is the "system of record" for dependencies and (only) those will be treated as transitive dependencies that need to be figured out (version-wise) for things that need to be downloaded.

crinklywrappr21:03:46

Thanks Sean. Sorry for asking twice. 🥴

seancorfield21:03:22

I thought it sounded familiar 🙂

crinklywrappr22:03:48

Sorry for obsessing about this but it sounds like this makes dependency management more difficult because you can't guarantee that a maven coordinate will pull in all the dependencies...and you can't pull non-maven coordinates with leiningen.

dpsutton22:03:08

maven coordinates need to specify their dependencies in pom.xml. If you do this, you will have all of your dependencies

crinklywrappr22:03:31

that's a suitable answer if i control everything in the stack

dpsutton22:03:11

i don’t follow. a well formed jar lists its dependencies in a pom.xml. If you are publishing the jar, which i’m getting from “if i include deps.edn in jar files published to clojars” then you need to make your jars correctly.

dpsutton22:03:50

but perhaps you could back up and explain your problem rather than trying to solve it with deps.edn in a jar file. Explain the actual issue you are trying to accomplish

crinklywrappr22:03:50

I see an issue with the ecosystem and I'm trying to find someone to tell me that I'm nuts or overlooking something. pom.xml doesn't include https://clojure.org/reference/deps_and_cli#_git. If a library specifies a gitlib in deps.edn, then any dependants on that library won't receive that gitlib dependency if they rely on my library from clojars. If that gitlib dependency is not on maven at all, then leinengen users can't use the library. If I maintain a dependant on the library, then I can work around this problem like you said - I can fork both dependencies and consume them however I want. But, uh... that's not a good solution.

seancorfield22:03:42

If you're publishing a library to Clojars/Maven, it's on you to do it correctly -- and that means no git dependencies.

seancorfield22:03:49

If a project has git deps, it can't be packaged as a JAR for Clojars/Maven -- it can only be consumed from source via git deps, i.e., deps.edn projects and the CLI.

dpsutton22:03:02

That’s correct. I think there has been some writing on this. The clojure cli allows you to build a classpath using projects hosted on github by cloning them and adding them to the classpath. This is considered a dev time helper largely. And this is a functionality that is offered by the Clojure cli and not the java ecosystem as a whole.

seancorfield22:03:06

CLI-specific tooling can (and often is) provided as git deps only. Some people occasionally request such tooling be packaged as a JAR that can be consumed from Clojars (or Maven) but it is up to the author to decide whether or not that is appropriate.

seancorfield22:03:47

@doubleagent Do you have a specific library in mind for this question or is this an abstract consideration?

crinklywrappr22:03:19

It's an abstract consideration. Personally, I think this approach is dragon-territory because it relies on good actors. If clj merged dependencies from pom.xml and deps.edn then it would be tenable even if it left Leiningen users in the cold for a while. I've followed Clojure for over ten years and have been using it professionally for seven, but I'll have to consider things before crossing this bridge.

dpsutton22:03:26

I’m not following the confusion. If you are relying on maven coordinates for your stuff, you know you are not using the gitlibs functionality. If you elect to use coordinates based on gitlibs, you have elected into it and you know that its not going in a jar. It seems straightforward to me.

seancorfield23:03:17

☝️:skin-tone-2: Exactly this. I don't see how it's an issue @doubleagent

seancorfield23:03:15

I have a bunch of OSS projects. Most are published as JARs to Clojars (and do not use git deps internally). Some are deliberately git deps (and are not published as JARs because of that).