This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-04
Channels
- # aleph (2)
- # beginners (80)
- # boot (18)
- # cider (6)
- # cljs-dev (14)
- # cljsrn (5)
- # clojure (114)
- # clojure-android (5)
- # clojure-dev (8)
- # clojure-greece (6)
- # clojure-italy (9)
- # clojure-russia (108)
- # clojure-uk (82)
- # clojurescript (158)
- # css (1)
- # cursive (21)
- # data-science (1)
- # datomic (66)
- # emacs (9)
- # ethereum (3)
- # fulcro (26)
- # graphql (7)
- # hoplon (25)
- # juxt (2)
- # keechma (34)
- # lein-figwheel (4)
- # leiningen (2)
- # off-topic (4)
- # om (5)
- # onyx (14)
- # parinfer (2)
- # pedestal (17)
- # planck (3)
- # portkey (14)
- # re-frame (23)
- # reagent (12)
- # ring (8)
- # rum (1)
- # shadow-cljs (506)
- # spacemacs (2)
- # vim (11)
- # yada (6)
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
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.
http://cljsrn.org/ this uses cljs. using clojure maybe https://github.com/clojure-android/lein-droid
And Cider shows the param-string (like http://clojuredocs.org 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.
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. 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)
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?
@hlolli I suggest you to have a look to this middleware https://github.com/puppetlabs/ring-middleware/blob/master/src/puppetlabs/ring_middleware/core.clj#L56
Is there a way to use alter-var-root on clojure.core functions? Doesn’t seem to have any effect in the REPL.
@U051SA920 Oh, awesome. So would setting this in leiningen work? :jvm-opts ["-Dclojure.comipler.direct-linking=false"]
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.
@U060FKQPN There’s absolutely no way to get clojure.core functions non-directly linked? Would I have to recompile Clojure?
There is some talk about it here: https://dev.clojure.org/display/design/Build+Profiles
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)
org.quartz.impl.StdSchedulerFactory.
(doto .initialize)
.getScheduler
.start))
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)
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
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 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?
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 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
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
(assuming the clock is correct across the 200 vms, so cron actually runs at the same time)
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
hm ok. Sucks! Thanks @noisesmith @bfabry
@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 — https://github.com/stuartsierra/component There is also the related https://github.com/danielsz/holygrail which works with boot
@the2bears I released what I was working on! https://github.com/lincoln-b/mortimer
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! 🙂
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
@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 def
s at the top-level -- not inside a defn
(just checking!)
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 https://github.com/juxt/bidi#multiple-routes
(link is directly to an example in the readme)
thank you @noisesmith @seancorfield