Fork me on GitHub
#clojure
<
2016-04-01
>
arrdem02:04:23

@richiardiandrea: where's the patch? This is something I've been thinking about for a while.

richiardiandrea02:04:59

Still need to remove warnings and polish boot parallel...tomorrow

richiardiandrea02:04:21

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.

richiardiandrea02:04:23

Of course everything is super alpha

martinklepsch11:04:46

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?

jonathanj11:04:40

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

jonathanj11:04:48

Oops, forgot the link to system itself: https://github.com/danielsz/system

martinklepsch11:04:35

@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

martinklepsch11:04:44

system is based on component afaik so I think the problems are similar in the case described above

jonathanj11:04:57

What’s an application container in this context?

martinklepsch11:04:39

something like nginx-clojure, AWS Elastic Beanstalk probably Heroku as well

nberger12:04:40

@martinklepsch your handler might depend on other components, so it sometimes make sense for it to be a component too

nberger12:04:43

And it could be a slightly different one for prod and dev, to use different middleware maybe

martinklepsch12:04:20

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

pesterhazy12:04:47

Is there a test runner for clojure.test that supports a "stop-on-failure" flag (like phpunit)?

pesterhazy12:04:47

@martinklepsch: I don't understand the problem

pesterhazy12:04:08

there's an http-server component that takes the routes as an argument, right?

martinklepsch12:04:30

@pesterhazy: in an application container you don't expose a port but rather a ring handler

nberger12:04:34

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

nberger12:04:19

anyways, not sure if I'm being of any help, and I have to run... I'll be back later to read the conclusions 😄

pesterhazy12:04:34

ah so the problem is that the app container doesn't support a parametrized handler

martinklepsch12:04:38

I think I need to start the system beforehand so I can pass define the handler globally

martinklepsch12:04:48

@pesterhazy: exactly, it just wants a var

pesterhazy12:04:24

then it's bound to be ugly anway

Chris O’Donnell12:04:41

@martinklepsch: you should be able to pass the handler as a dependent component to your server component

martinklepsch12:04:12

@pesterhazy: that's what I'm realizing as well 😄

pesterhazy12:04:16

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

pesterhazy12:04:39

that's as good or bad as a port to listen on (which is a sort of global variable as well)

Chris O’Donnell12:04:41

ah, oops. I misread your problem!

sveri12:04:50

@martinklepsch: are you talking about stuarts component library?

sveri12:04:41

the handler itself is not a var here and the constructor function accepts arguments. Does that help?

pesterhazy12:04:59

@sveri, that doesn't use the ring lein plugin though, right?

sveri12:04:15

@pesterhazy: Exactly, just some ring libs

lewix12:04:06

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)

martinklepsch12:04:14

@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

danielsz12:04:39

@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

martinklepsch12:04:39

@danielsz anything in particular? it does not define a global handler var somewhere does it?

danielsz12:04:14

Ah, sorry, I thought you wanted to get rid of the global handler var.

nberger12:04:02

@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

sveri12:04:04

Yea, that was my assumption too, sorry

martinklepsch12:04:06

@nberger: yeah, I basically just define it based on some env parameter now

martinklepsch12:04:26

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

martinklepsch13:04:34

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

martinklepsch13:04:16

boot repl also works fine

martinklepsch13:04:37

anyone an explanation/idea?

danlebrero13:04:14

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

danlebrero13:04:19

unless you are writing some script, you should avoid creating DB connections, Thread Pools, make HTTP request and such things when loading a ns

sveri13:04:37

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

martinklepsch14:04:14

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

john.carnell14:04:41

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

danlebrero14:04:57

@sveri no clue, does the repl start if you comment out the doseq?

martinklepsch14:04:17

let me create a repro

john.carnell14:04:34

figured it out nevermind

peterschwarz15:04:59

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

john.carnell15:04:17

Going to try that

peterschwarz15:04:18

And I missed your "figured it out" simple_smile

john.carnell15:04:28

No thought I did

john.carnell15:04:40

Basically I am porting some code from go to clojure

john.carnell15:04:16

and there are some subtle differences in the way the byte array is being handled

john.carnell15:04:20

at least I think there is

ghadi15:04:26

The usage is on line 34

john.carnell15:04:21

@peterschwarz: That did the job. I was trying (drop 12) Whats the difference between take and drop

john.carnell15:04:28

take-last and drop

peterschwarz15:04:26

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.

martinklepsch15:04:28

tl;dr if user.clj or namespaces it depends on contain something like (deref (future #(do thing))) the deref will block forever

fasiha15:04:21

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?

fasiha15:04:45

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

hiredman15:04:55

how tied are you too the socket repl? it is pretty easy to embed nrepl

hiredman15:04:14

(for which most editors have clients)

fasiha15:04:05

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)

sveri15:04:45

@martinklepsch: ah, the user namespace. It's more famous than it should be, I guess.

hiredman15:04:18

talking to nrepl is a little more involved than the socket repl, so you will want to use some kind of client

fasiha15:04:50

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

fasiha15:04:10

Will nrepl let me connect to the actual process that it's invoked from, to support the above usecase?

hiredman15:04:07

lein repl is built on nrepl

fasiha15:04:14

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 simple_smile!

fasiha17:04:57

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

bwstearns19:04:57

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?

hiredman19:04:02

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)

hiredman19:04:27

the functions from clojure.repl are automatically available from the user namespace

hiredman19:04:29

so (clojure.repl/doc ...) should work, or (require '[clojure.repl :refer [doc]]) should make your original doc call work

hiredman19:04:06

it is super annoying

bwstearns19:04:13

doc is kinda nice to have everywhere

bwstearns19:04:28

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>

hiredman19:04:11

eastwood has a linter for docstring placement

hiredman19:04:49

(it is not an uncommon mistake)

bwstearns19:04:33

I think it aesthetically looks nicer after the args, but again, I get why it makes more sense before the args.

nkraft20:04:09

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.

jr20:04:17

here’s the problem

(defn foo []
  “is this a doc string or body?”)

nkraft20:04:14

To me it's just as unclear if the [] appears after the docstring.

nkraft20:04:41

At least it's easy to find the args, though.

hiredman20:04:59

that is not even the problem

hiredman20:04:37

(fn [] ...) is actually sugar for the multi-arity form (fn ([] ...))

hiredman20:04:49

and defn is built on top of that

hiredman20:04:07

(defn x ([...] ...) ([...] ...))

nkraft20:04:10

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.

hlship21:04:27

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.

hlship21:04:55

Ok, I think that part is just a coincidence.

hlship21:04:44

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.

hlship21:04:32

Nah. Probably not.

hlship21:04:34

[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

hiredman22:04:03

oh, of course, it is because of how the tests are being run from maven

hiredman22:04:39

when maven runs the tests, ns isn't the namespace of test, so eval explodes

hiredman22:04:46

if you use syntax quote it should work

hiredman22:04:38

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

hlship22:04:14

Thanks for the help; very confusing that ns is not the namespace with the executing code! Feels like JavaScript all of a sudden. Anyway, 0 failures now, thanks!