Fork me on GitHub

I know clojure.core is compiled with direct linking - is clojure.test also?


All of clojure.jar is direct linked

Jan Drake01:10:29

Greetings fellow Clojurians.


I'm trying to use hugsql with component, and I'd like to be able to call the def-db-fns macro from within a specific namespace, to have the query functions reloaded in that namespace


so.. i guess i need to wrap the function call in something which sets the namespace just for that call


bit off in the weeds, any help appreciated..


nevermind, hugsql/map-of-db-fns is much better to use from component.


I have a unit test that works perfectly fine in java but fails in clj/repl. pretty sure it has something to do with annotations, what could be wrong and/or any ideas how to debug this?


exactly the same implementations in the two unit tests. the code is testing xml deserialization with xstream, and the java code has been working for years. some of the simple unit tests work in clj as well


@kaosko You're going to need to share more details -- a link to the code maybe -- for us to provide any sort of input of that.


what's the state of clojure on android?


or what's the most clojurey thing I can use that works well on android?


I’m constantly being tripped up by when-let doc-string:


(or rather the paramter names)


(when-let bindings & body)


since it only allows one binding.


anyone else feeling this is a problem?


not really as the multiple binding possibility would be quite ambiguous


yeah, I’m not arguing for multiple bindings


I’m arguing for a change of parameter name/doc-string


Since a parameter name which is plural which only accepts a singular is strange.


yeah the docstring could be improved


And Cider shows the param-string (like do.)


Hi all, can you help me with the following? I have a namespace for the svc layer, and I want to return meaningful values/errors from the svc layer to later be converted to http responses; I could return a map {:status :found|:notfound|:ok} or similar and map that on the http layer, but was wondering whats the clojure way of doing this. Was taking a look at


@mping I am facing similar issues, returning map plays well if I don't have multiple functions working on a value in that case I could return the status straightaway. In case the values are being threaded through multiple functions then this becomes a problem. i try to use nil puning in those cases but there is a problem in relaying the correct error message. Note that, I am still learning clojure so I could be missing sth obvious. It would be wonderful to know what the idiomatic solution would be to this problem.


mping I think the way you’re doing it currently is Clojure-y 🙂


I apologize if this is silly, but lets consider this snippet (some-> user login get-token) If there is some error in the login, what I try to do is return nil so the chain fails but I am unable to get the error cause (eg. pass incorrect). Now to return such error cause, is raising an exception a good way or am I missing sth here.


@shakdwipeea I think exceptions are the accepted way to do this in Clojure. is similar to what you're doing with nil's, but allows you to add an error (sort of in like metadata)


Thanks, I will check it out


I want to make trough clojure a proxy server where I can rewrite the url of some chosen requests. I see by searching with google that there are few proxy libraries: ring-proxy, ring-request-proxy, clj-http-proxy and http-kit. Some recommendation of which one to use?


aaa nice @msprunck thanks!


Is there a way to use alter-var-root on clojure.core functions? Doesn’t seem to have any effect in the REPL.


See "direct linking"


@U051SA920 Oh, awesome. So would setting this in leiningen work? :jvm-opts [""]


I’m having trouble with that still for some reason…


I think clojure.core will always be directly linked. Not sure you can redefine functions in there. But Maybe @U060FKQPN can confirm this.


you can redefine functions for later usage


but you can't redefine clojure.core functions that have already been directly linked


@U060FKQPN There’s absolutely no way to get clojure.core functions non-directly linked? Would I have to recompile Clojure?


clojure doesn't distribute a version of itself non directly linked


Though, it seems there is no "dev" or "dynamic" :classifier for clojure on maven.


build profiles aren't a thing


that's a confluence page for things that might eventually happen


can't you exclude functions? then def them to the core implementation and then redef to your custom implementation?


you can redef core functions so that functions not compiled with direct linking enable will see the redefinition


but the code that ships with clojure has already been direct linked so you can't redef a clojure.core function and have another clojure.core function use the redefined version


That’s good to know, thanks again @U060FKQPN for your wisdom


I know the percentage of actual semi enterprise production clojurists on here is low comparatively, but is there any chance anyone on here has used a quartz scheduler in clojure before with a durable backend on multiple environments?


I haven’t tried quartz and learned of it after I wrote a scheduler which we have used in several production services. I have tried Chime and found it to be buggy. Rolling your own with core.async really isn’t hard. We may be able to eventually open-source ours, but it is complicated unfortunately 😞


I have a prod quartz implementation in Java for work, any confusing parts of config that aren't clojure implementation specific I could probably help with. I'm also planning on spinning this implementation out into a standalone service using clojure so we could try to hack this out together @tjtolton


thanks, @U774Z4VJA! I actually did get it working. I built a function that allows you to generate and start a scheduler from a properties map. I basically built a properties object using java.util.Properties, added the values from the map to it, then built a STDSchedulerFactory from that properties object, then called getFactory on that object. Took a but of java reading, but I got it working. In case you're curious, heres what the function looks like (I'm testing it for correctness now)

(defn scheduler-with-config [config]
  (-> (reduce #(doto %1 (.put (key %2) (val %2))) (java.util.Properties.) config)
      (doto .initialize)


Sweet, thanks for sharing, this will save me a lot of pain when I get around to doing this (probably a month away)


cool. be sure to save this off in a separate place for yourself, @U774Z4VJA clojurians only keeps history up to a certain number of messages and then it removes them in order of age. (I've lost cool snippets that way before)


yep for sure thx for the reminder @tjtolton 🙂


the quartz config stuff is real confusing to me..


I think I have to override the scheduler factory class in order to set some properties on it.. kind of hack in my environment specific config values.. but that's a level of interop I've not attempted yet


@tjtolton I work in a semi enterprise. every time I've been tempted by that thing I've just installed or used an existing airflow instance to run a java -jar command


lol, tell me about it.


I would love to use quartz just once, but every time I try to use it in a system someone decides a cronjob would be simpler, or to write our own scheduler, or some other crazy thing


I read the source to quartz & wasn't hugely excited, The locking strategy using jdbc seemed a little confusing to me, like it might be a hack.


(I'm saying that to be corrected btw!)


I am not saying it is some tower of virtue, I am saying someone has written a drop in library that does this, why must I continue to reinvent it?


but then, what is the benefit over cron or a clojure-cron


using an acid database (or god forbid a non-acid database) to implement a distribute mutex is not uncommon


@seancorfield related to my last night's issue, the case is exactly the same as in when I'm running an Xstream related unit test in repl, it's like the annotations in my java class are not read at all. same code works in plain junit test in the same project. very interesting problem and I'm rather baffled at this point


Can you explain a bit more about the workflow where you are "running an Xstream related unit test in repl"? Are you testing Java code or Clojure code at that point?


it will depend on your deployment environment, but cron runs the same thing everywhere the same crontab is installed


and you want to install the same crontab everywhere to reduce the differences between the 200 odd vms you are running on


but you very often have a task you don't want to spin on up 200 copies of


(assuming the clock is correct across the 200 vms, so cron actually runs at the same time)


distributed schedulers lead to distributed locks


I am doing some interop with Stanford CoreNLP and I want to be able to use Clojure's count function on one the classes in there, which is not a collection type. The class does have a .count() method, though. I thought Clojure might have a way to make this work by metaprogramming, but I haven't discovered how.


@simongray sadly count is implemented on the java side, with Interfaces rather than Protocols


@simongray count appears to delegate to pure java land for performance reasons. so you won't be able to make that work


one approach would be to make a new type that delegates to the class as its super for everything it does, and implement Counted in that type * fixed name of Interface


but that seems to be a lot of effort for a small benefit


@waffletower yes, I used as-> with mixed arities


are there any clojure libraries/frameworks that provide the same kind of hot-reloading as figwheel?


Hi everyone! Here is Clojurecademy DSL link if anyone interested in creating Clojure based courses on Clojurecademy


@lilactown use of the “reloaded” workflow is one approach — There is also the related which works with boot


I can’t overstate how awesome everyone’s been at answering my questions. Seriously. Made the project a heck of a lot more enjoyable 🙂


Clojure should be all about having fun! 🙂


It is until the you get one of the awesome exception / stack traces


Hi! I have some code that wraps a java library as such:

(defn java-wrapper
  "calls a variadic java function of the form Function(String... values)"
  [a-string string-vec]
  (.Function an-object a-string (into-array String string-vec)))
In the rest of the program, I call this function with a string (computed at runtime) and small static set values for the vec argument:
(java-wrapper dynamic-string1 ["foo"])
(java-wrapper dynamic-string2 ["bar"])
Those are in a hot loop. It seems like I'm paying the cost of into-array. Given that those arguments are known in advance, I feel like those into-arrays could be done once when the program starts and be reused. Any elegant solution to do that?


you could refactor and make it take a string array


You mean like

(def foo-arg (into-array String ["foo"]))
(.Function an-object a-string foo-arg)


yeah, even that works - into-array is smart enough not to do that job twice, right?


(I'd be suspicious of your java-wrapper function operating on an-object that it is not passed as an argument -- globals are bad(tm)...)


The def would run once, when the ns is loaded (so each separate set of known-in-advance arguments would be set up once at startup).


@pelletier also, as a style consideration, I’d avoid using the term “Function” for things that are not java.util.funciton.Function or clojure.lang.IFn because methods are a completely different thing (I mean, I think I know what you mean here but clarity does help)


this is not the actual code 🙂 the an-object is not actually global, and .Function has a different name


but you're right


@seancorfield so one def for each value I have and then use the appropriate right?


Based on what you've shown so far, yes, that sounds right.


or just hold the string array in a local binding and reuse - whatever matches your real usage


And the defs at the top-level -- not inside a defn (just checking!)

Jim Rootham23:10:23

I have a small Clojure backend using ring to an Elm SPA. I need to expand it from 4 actions with common return values (json) to 6 with 3 return values (all still json). I do not currently use routes but the extension to multiple returns suggests that I do so. Compojure has been suggested as a solution. A brief perusal suggests that it is over complicated for this task. Is it easier to use than it looks? Or is there a simpler (reasonably supported) library that will do this?


bidi is pretty straightforward - it lets you describe some routes with data (as opposed to compojure which defines a routing DSL)


@jrootham for example, this should be close to what you need


(link is directly to an example in the readme)