Fork me on GitHub
#clojure
<
2021-05-05
>
matheusashton00:05:22

Hello, I'm having an issue with clj-kondo and honeysql because honeysql helpers are macros and clj-kondo doesn't recognize those macros. I tried configuring clj-kondo as in honeysql's https://github.com/seancorfield/honeysql/blob/develop/.clj-kondo/config.edn but now, instead of a unknown symbol warning, I'm getting an error because it expects (select :field1 :field2 :field3) to have only 2 arguments.. anyone had issues like this before?

seancorfield01:05:50

Ask in #clj-kondo but I think there’s a “catch-all” def style linter you can have it lint-as that might help?

matheusashton02:05:25

I'll put the question there

lgessler00:05:19

I want to ship an uberjar foo.jar to my users that will allow them to optionally create a sibling file config.edn if they want to override defaults. what's the right way of locating this config.edn in my code so I can read it?

hiredman01:05:15

Depends, using -D to set a jvm property to point to the file and read it is not uncommon

👍 3
hiredman01:05:13

Depending on how your uberjar is being used you might stipulate that the config file be on the classpath and use io/resource to load it

hiredman01:05:02

(combining classpath specification with uberjars can be a little whacky though)

lgessler01:05:21

oh duh, yeah, making it a param is not a bad idea. still curious about whether there's a not-terribly-hacky answer to my original question though

hiredman01:05:06

The user.dir system property gives you the current working directory when the jvm is launched, but that may not have anything to do with where your jar file lives

hiredman01:05:24

You can do something like look up a resource you know is in your jar, the url you get back will have the path to your jar file in it, so munge that

👍 3
lgessler01:05:52

nice! all good ideas, thanks

Janne Sauvala17:05:39

Does anyone know good tutorials, articles or example repos of good ways to wrap Java/JS libs with Clojure(Script)? I’m interested in looking best ways to wrap libs that are mutating their internals and how to handle those smoothly in Clojure

vemv18:05:36

some quick tips on making lib's mutability more safely consumable: - wrap the op under a threadlocal - create an object once per defn invocation and don't let references to it 'escape' to callers

vemv18:05:04

the core idea is that a properly designed OOP lib, though mutable, will have that mutability limited to single objects (vs. global mutability). So it's fairly easy to control a single object

emccue18:05:34

In general though if a lib is a stateful thing and that statefulness can't be "contained" then you will need to use the standard mechanisms for controlling that

emccue18:05:45

e.g. the system pattern

emccue18:05:17

obvious sort of example would be a database pool

emccue18:05:47

and maybe that means there isn't going to be much benefit to doing a clojure wrapper beyond syntax convenience

Janne Sauvala20:05:28

Thanks for the examples and tips. Like Ethan said, I think in my case that I have been thinking most of the benefit is coming from the nicer syntax when using with Clojure. It started to be quite tedious to write interop code all the time so I’m thinking about writing a wrapper to do my bidding

walterl22:05:47

What's the idiomatic way to apply a decorator to a function defined with defn? Replace the defn's with (def decorated (decorator (fn ...)))?

dpsutton22:05:08

(defn foo [])
(alter-var-root #'foo decorator)
i saw tim baldridge do this with memoize and thought it was interesting

walterl22:05:26

That certainly looks better, thanks! 🙌

walterl22:05:26

Best of all, it doesn't offend Eastwood in the way that my re-def-ing did 😅 🎉

rutledgepaulv22:05:33

another option:

rutledgepaulv22:05:48

(defmacro defmemo
  "Define a function with a memoized implementation."
  [& defnargs]
  `(doto (defn ~@defnargs)
     (alter-var-root #(with-meta (memoize %1) (meta %1)))))

Ben Sless06:05:49

I always wandered how that interacts with direct linking and aot compilation. Anything I should be wary of?

🤷 2