This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-01
Channels
- # aatree (3)
- # admin-announcements (2)
- # beginners (42)
- # boot (142)
- # cider (12)
- # cljsrn (11)
- # clojure (126)
- # clojure-greece (2)
- # clojure-poland (7)
- # clojure-russia (81)
- # clojure-uk (10)
- # clojurescript (81)
- # component (27)
- # core-typed (2)
- # cursive (18)
- # euroclojure (1)
- # gorilla (1)
- # hoplon (85)
- # immutant (2)
- # jobs (3)
- # leiningen (2)
- # off-topic (49)
- # om (151)
- # onyx (19)
- # parinfer (3)
- # re-frame (36)
- # reagent (2)
- # spacemacs (5)
- # untangled (32)
- # yada (9)
@richiardiandrea: where's the patch? This is something I've been thinking about for a while.
Still need to remove warnings and polish boot parallel
...tomorrow
It is not the feature per se that I am happy about, but the fact that (to me) is very readable and this is because boot has been ingeniously thought out. Tasks are key.
Of course everything is super alpha
when using component
how do people deal with application containers that take a ring handler? do you just define the handler toplevel if running in a prod context or is there a more clever way?
I like @danielsz’s system
for that better than component, it makes that sort of thing a bit easier. Here’s a complex example you should read after understanding how system works: https://github.com/danielsz/system-duct-style-example/blob/d02bbe46b2d2851549fd91d839ef7ee8f96c5999/src/example/systems.clj
Oops, forgot the link to system itself: https://github.com/danielsz/system
@jonathanj: if you have an app container that requires a my.app/handler
type of thing you'll still need to instantiate the system at some point and globally def. that handler
system is based on component afaik so I think the problems are similar in the case described above
something like nginx-clojure
, AWS Elastic Beanstalk probably Heroku as well
@martinklepsch your handler might depend on other components, so it sometimes make sense for it to be a component too
And it could be a slightly different one for prod and dev, to use different middleware maybe
@nberger: my handler is a component. It just seems like I'll need something like this to define it globally for the container:
(def handler
(-> {:handler-fn app}
components/oc-system
(dissoc :server)
component/start
(get-in [:handler :handler])))
Is there a test runner for clojure.test that supports a "stop-on-failure" flag (like phpunit)?
@martinklepsch: I don't understand the problem
there's an http-server component that takes the routes as an argument, right?
@pesterhazy: in an application container you don't expose a port but rather a ring handler
oh, so the container needs to get the "started" handler... One thing to note is that it seems you are not worried about stopping the system.... I guess whether you have it globally or not also depends on whether there are other "parts" of your app that need access to this handler (or other component), and also if you need the system to be started beforehand, or if you can start it just when the container needs to get to it
anyways, not sure if I'm being of any help, and I have to run... I'll be back later to read the conclusions 😄
ah so the problem is that the app container doesn't support a parametrized handler
I think I need to start the system beforehand so I can pass define the handler globally
@pesterhazy: exactly, it just wants a var
then it's bound to be ugly anway
@martinklepsch: you should be able to pass the handler as a dependent component to your server component
@pesterhazy: that's what I'm realizing as well 😄
if you're stuck with a simple var, not just have a global var handler
which you alter-var-root
when the component is mounted
that's as good or bad as a port to listen on (which is a sort of global variable as well)
ah, oops. I misread your problem!
don't mind me
@martinklepsch: are you talking about stuarts component library?
This is how I usually use them with the ring handler: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/components.clj
https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/handler.clj
the handler itself is not a var here and the constructor function accepts arguments. Does that help?
@sveri, that doesn't use the ring lein plugin though, right?
@pesterhazy: Exactly, just some ring libs
anytone tried golang before? How does it compare in terms of ecosystem, productivity and community? (assuming that you're can have an objective opinion without bias)
@sveri: I have a similar setup, i.e. a function that takes a system and returns a handler. Unfortunately this kind of setup doesn't play nice (by default) with things that expect a handler to be a globally defined var
@martinklepsch: I hope it's not too late to chime in, but please take a look at this: https://github.com/danielsz/system-dependency-injection
@danielsz anything in particular? it does not define a global handler var somewhere does it?
@martinklepsch: I guess I'd have a special namespace for the uberwar (you have an uberwar?), where I'd start the system and also expose the handler from there
@nberger: yeah, I basically just define it based on some env parameter now
(let [cnt (atom 0)
size 5
open (fn open [] (let [x (swap! cnt inc)] (println "new thing\n" x) x))
openers (doall
(map (fn open-pool [_]
(future (open)))
(range size)))]
(println "before block-start")
(doseq [worker openers] @worker))
Totally different thing: I have a top-level form that essentially does the above. When running this form in a REPL or as a boot script it runs through just fine but when running a lein repl that loads the containing namespace the REPL launch times out
boot repl also works fine
anyone an explanation/idea?
when the ns is loaded, the code is executed. If the code execution takes several minutes to run, lein will decide that something went wrong and will abort
unless you are writing some script, you should avoid creating DB connections, Thread Pools, make HTTP request and such things when loading a ns
@martinklepsch: Also wenn you create a jar of it it will execute the code during jar generation (see AOT compilation for that). Which has the same problems as @danlebrero just described.
@sveri: @danlebrero right, everything you said is true but given the code example above — how is it ever going to take long enough to make the REPL time out?
Hey guys try to pull the last 12 places in a byte array in clojure. Any suggestions on the most idiomatic way to do this
@sveri no clue, does the repl start if you comment out the doseq?
@danlebrero you surely meant @martinklepsch
@sveri, yeah sorry!
let me create a repro
figured it out nevermind
@john.carnell: perhaps you want to look at https://github.com/ztellman/gloss
Nice thanks
@john.carnell: if it's just a byte array (not a bitmap), you can simply do (take-last 12 my-byte-array)
- if it needs to be a byte array result, wrap it in a call to byte-array
and you're good to go.
thank you
Going to try that
And I missed your "figured it out"
No thought I did
Basically I am porting some code from go to clojure
and there are some subtle differences in the way the byte array is being handled
at least I think there is
@peterschwarz: That did the job. I was trying (drop 12) Whats the difference between take and drop
take-last and drop
@peterschwarz: appreciate the help
drop
will get rid of the first 12 of the sequence, which will only give you the right result, in your case, if your array is 24 elements.
@danlebrero: @sveri I figured it out! https://github.com/martinklepsch/user-future-deref-block
tl;dr if user.clj or namespaces it depends on contain something like (deref (future #(do thing)))
the deref will block forever
I was starting a clojure.core.server REPL from lein via :jvm-opts
defined in my defproject
map per http://stackoverflow.com/a/34932745/500207, but I had to stop doing that now that I sometimes try to run two or more lein commands at the same time (server, figwheel, etc.). Is there a way I can programmatically embed a REPL in my running webserver, perhaps by calling a clojure.core.server
function after http-kit's run-server
, instead of through a JVM option?
(I tried calling clojure.core.server
's repl
function after http-kit's run-server
and that gave me a REPL but in user
namespace, and not in the environment that invoked it)
Not tied to socket repl at all, since I didn't know nrepl was an option (I only found out about socket repl from the 1.8 release docs, and alas have never looked into what nrepl does despite seeing it mentioned here and there)
@martinklepsch: ah, the user namespace. It's more famous than it should be, I guess.
talking to nrepl is a little more involved than the socket repl, so you will want to use some kind of client
So I want to mention that from lein repl
(and presumably this socket REPL) I can get into the namespace that my server was launched for—but the REPL won't be connected to the process running my server. In my case, I have an atom that, when it changes, http-kit does something, and I was using socket repl to modify that atom for testing
Will nrepl let me connect to the actual process that it's invoked from, to support the above usecase?
Sorry, I could have been clearer above: plain lein repl
doesn't do what I want because, while it'll let me enter the namespace that contains the webserver code & atom, reset!
ing the atom in lein repl
doesn't trigger the change in my webserver because (duh) that REPL isn't in the process that's running my webserver (I do feel ridiculous for not understanding that). But I'll try nrepl and my editor !
@hiredman: thanks, nrepl did the trick 😄! (defonce server (start-server :port 17888))
in my code, then lein repl :connect localhost:17888
dropped me into user
ns but after switching to my handler ns, I had access to my webserver's state 🙌
Two quick questions for any gorilla-repl users: I'm getting unable to resolve symbol doc when trying to evaluate (doc gorilla-repl.image), any ideas why doc isn't available? Secondly, how does one include images in a notebook?
doc got moved out of clojure.core awhile back, it is now in some other namespace, maybe clojure.repl, and clojure.repl is not automatically available in new namespaces (while clojure.core is)
so (clojure.repl/doc ...)
should work, or (require '[clojure.repl :refer [doc]])
should make your original doc call work
though writing the docstring before the args drives me a bit crazy/I always forget (I get why it might make more sense that way with the lisp syntax). </tangent>
I think it aesthetically looks nicer after the args, but again, I get why it makes more sense before the args.
I agree with @bwstearns about the placement of docstrings. I also think they look better after the args, and when I look at a function, often the first question I have is "what are the args?". Having to wade through long docstrings sometimes makes that more difficult than it has to be. As long as docstrings are short, it doesn't matter to me where they go. It's the long ones that are problematic.
Didn't say it could or should be fixed. Just one of those annoying things when writing Clojure code. Not that I'm complaining, that list is pretty short compared to other languages.
I’m having a problem working on http://dev.clojure.org/jira/browse/CLJ-1908. Background: I’ve added run-test macro to clojure.test. It works in the REPL, but in mvn test
it fails.
It feels like that the clojure 1.8 version of clojure.test is perhaps on the classpath, & obscuring the version in src/clojure and/or test/classes.
[INFO] org.clojure:clojure:jar:1.9.0-master-SNAPSHOT
[INFO] +- org.codehaus.jsr166-mirror:jsr166y:jar:1.7.0:provided
[INFO] +- org.clojure:test.generative:jar:0.5.2:test
[INFO] | +- org.clojure:tools.namespace:jar:0.2.10:test
[INFO] | \- org.clojure:data.generators:jar:0.1.2:test
[INFO] \- org.clojure:test.check:jar:0.5.9:test
if you put a '(prn ns)' right before the call to eval, it will print something like #<Namespace user> or #<Namespace clojure.core>, however namespace objects print