Fork me on GitHub
#clojure
<
2017-10-04
>
cfleming01:10:30

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

ghadi01:10:44

All of clojure.jar is direct linked

Jan Drake01:10:29

Greetings fellow Clojurians.

minikomi04:10:32

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

minikomi04:10:38

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

minikomi04:10:49

bit off in the weeds, any help appreciated..

minikomi05:10:21

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

kaosko05:10:36

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?

kaosko05:10:42

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

seancorfield06:10:33

@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.

deadghost08:10:30

what's the state of clojure on android?

deadghost08:10:07

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

slipset08:10:59

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

slipset08:10:17

(or rather the paramter names)

slipset08:10:28

(when-let bindings & body)

slipset08:10:39

since it only allows one binding.

slipset08:10:32

anyone else feeling this is a problem?

mpenet08:10:24

not really as the multiple binding possibility would be quite ambiguous

slipset08:10:40

yeah, I’m not arguing for multiple bindings

slipset08:10:58

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

slipset08:10:25

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

mpenet08:10:27

yeah the docstring could be improved

slipset08:10:57

And Cider shows the param-string (like http://clojuredocs.org do.)

mping08:10:52

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

shakdwipeea09:10:34

@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.

schmee09:10:18

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

shakdwipeea09:10:33

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.

dominicm10:10:23

@shakdwipeea I think exceptions are the accepted way to do this in Clojure. https://github.com/adambard/failjure/blob/master/README.markdown is similar to what you're doing with nil's, but allows you to add an error (sort of in like metadata)

shakdwipeea10:10:39

Thanks, I will check it out

hlolli12:10:42

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?

hlolli12:10:59

aaa nice @msprunck thanks!

chalcidfly13:10:51

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

rauh13:10:44

See "direct linking"

chalcidfly14:10:42

@U051SA920 Oh, awesome. So would setting this in leiningen work? :jvm-opts ["-Dclojure.comipler.direct-linking=false"]

chalcidfly14:10:48

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

rauh14:10:51

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

bronsa14:10:38

you can redefine functions for later usage

bronsa14:10:49

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

chalcidfly14:10:06

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

bronsa14:10:44

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

rauh14:10:11

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

bronsa14:10:08

build profiles aren't a thing

bronsa14:10:19

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

dpsutton14:10:35

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

bronsa14:10:09

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

bronsa14:10:39

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

chalcidfly15:10:50

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

tjtolton15:10:31

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?

waffletower18:10:39

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 😞

metame20:10:40

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

tjtolton20:10:22

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)
      org.quartz.impl.StdSchedulerFactory.
      (doto .initialize)
      .getScheduler
      .start))

metame20:10:20

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

tjtolton20:10:43

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)

metame20:10:11

yep for sure thx for the reminder @tjtolton 🙂

tjtolton15:10:50

the quartz config stuff is real confusing to me..

tjtolton15:10:48

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

bfabry15:10:43

@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

tjtolton15:10:09

lol, tell me about it.

hiredman16:10:34

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

dominicm16:10:31

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.

dominicm16:10:15

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

hiredman16:10:30

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?

dominicm16:10:23

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

hiredman16:10:44

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

kaosko16:10:58

@seancorfield related to my last night's issue, the case is exactly the same as in https://stackoverflow.com/questions/18355495/xstream-duplicate-field-exception. 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

seancorfield17:10:58

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?

hiredman16:10:50

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

hiredman16:10:25

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

hiredman16:10:47

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

hiredman16:10:22

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

hiredman16:10:55

distributed schedulers lead to distributed locks

simongray17:10:05

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.

noisesmith17:10:56

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

bfabry17:10:03

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

noisesmith17:10:38

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

noisesmith17:10:48

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

misha17:10:55

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

lilactown18:10:04

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

Ertugrul Cetin18:10:39

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

waffletower18:10:36

@lilactown use of the “reloaded” workflow is one approach — https://github.com/stuartsierra/component There is also the related https://github.com/danielsz/holygrail which works with boot

chalcidfly19:10:13

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

seancorfield19:10:47

Clojure should be all about having fun! 🙂

genec22:10:03

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

pelletier22:10:14

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?

noisesmith23:10:12

you could refactor and make it take a string array

seancorfield23:10:23

You mean like

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

noisesmith23:10:47

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

seancorfield23:10:27

(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)...)

seancorfield23:10:12

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).

noisesmith23:10:22

@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)

pelletier23:10:06

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

pelletier23:10:08

but you're right

pelletier23:10:18

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

seancorfield23:10:41

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

noisesmith23:10:43

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

seancorfield23:10:03

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?

noisesmith23:10:15

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

noisesmith23:10:03

@jrootham for example, this should be close to what you need https://github.com/juxt/bidi#multiple-routes

noisesmith23:10:13

(link is directly to an example in the readme)