This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-07
Channels
- # aleph (3)
- # aws (7)
- # beginners (117)
- # boot (119)
- # cider (2)
- # cljs-dev (3)
- # clojure (193)
- # clojure-austin (1)
- # clojure-dusseldorf (4)
- # clojure-finland (5)
- # clojure-france (5)
- # clojure-italy (7)
- # clojure-portugal (1)
- # clojure-russia (204)
- # clojure-serbia (5)
- # clojure-spec (31)
- # clojure-uk (64)
- # clojurescript (288)
- # community-development (9)
- # core-async (54)
- # cursive (8)
- # datascript (18)
- # datomic (26)
- # dirac (8)
- # emacs (26)
- # figwheel (1)
- # hoplon (16)
- # jobs (2)
- # jobs-discuss (4)
- # juxt (1)
- # lein-figwheel (4)
- # leiningen (14)
- # london-clojurians (2)
- # lumo (17)
- # off-topic (44)
- # om (63)
- # om-next (2)
- # onyx (26)
- # perun (14)
- # planck (5)
- # portland-or (34)
- # proton (2)
- # protorepl (8)
- # quil (1)
- # re-frame (6)
- # reagent (16)
- # remote-jobs (4)
- # ring (7)
- # ring-swagger (10)
- # rum (1)
- # untangled (2)
I was wondering if there is a complete pom
generator for clojure out there...By complete I mean that it supports :parent
, properties
, distributionManagement
et al?
:thinking_face: Let's pretend for a moment I have a bot, which receives a message that tells it to evaluate a message. My namespace in the repl is dithcord.core
.
Now let's pretend when I get a messsage, it basically does (eval (read-string "(str *ns*)"))
. When I evaluate from the REPL I get dithcord.core
as expected, but when I run it from my message "handler" I get clojure.core
. I tried doing (binding [*ns* *ns*] (eval (read-string "(str *ns*)")))
but that doesn't seem to... change anything.
It's hard to explain exactly what's going on I admit my words fail me
This is a library, connecting to the Discord API. I have all this "bot" code running in memory, in the REPL, from that library's project. if that helps clarify things.
are you doing anything to change the *ns*
from the perspective of the handler? (like evaluating ns
or in-ns
etc?)
the default value of *ns*
is clojure.core
Right, but, what I mean is if I do something from the REPL which is... the same code running in memory it gives me one thing, but if it runs... hell how do I say this... "on its own" it's different
the repl is doing extra work (binding *ns*
) around every read/eval
who is invoking it when it runs “on its own”?
Basically, I receive a message from a websocket (aleph) which is pushed through a couple functions that eventually call this one
however, I defined that function in my REPL, not in my code, so it's only "in memory" if that makes any sense
I presume its in a thread that has not set a *ns*
where you defined it doesn’t matter
Basically it's straight-up in the repl, so no I didn't define a namespace other than what it loads from my core.clj file
the *ns*
you’re seeing is only contextually relevant in the thread running your repl
it’s a dynamic var with a per-thread binding
the repl is setting it in the repl thread
but that has no effect on the root binding, which is still clojure.core
Alright. So far I pretty much follow
so you need to do something in that message handler that sets a namespace context if that’s important to you
I'm guessing this would be different if I was actually running code from another project which required the lib, instead of doing all this in the repl, is that correct?
well, depends on the context of the thread that invokes it, so hard to say
Hmm. you know what let me try something real quick
Alright. Makes no difference if I run it from an actual project. So... the answer is, yes, I need to... "Force" a namespace, apparently, somehow
it would perhaps have unintended side effects, but you could alter the root binding of *ns*
well, actually, here the thing is, this test I did is running code that actually has (ns dtbot.core)
at the top
does it matter I'm just hitting "run in repl" in Cursive, like, does that alter the namespace
but again, that doesn’t affect the root binding
you are getting called back (I presume) from some other thread that doesn’t see the binding you’ve set in the test thread
Actually yes that sounds about right, it is a callback.
instead of binding *ns*
to *ns*
, why not bind it to the namespace you want it to be?
(binding [*ns* (find-ns ‘dtbot.core)] … )
Ah, right, that's what I was missing. find-ns
Let's see
Think this might be it, one sec to confirm
Perfect! Thank you very, very much Alex, that is the little tidbit of knowledge I was missing.
@qqq It doenst look like it knows about pos?
. I'd just copy the implmentation of double-in
and change it to float?
.
@qqq Don't know about the generators for that (although I am pretty sure I made that work at some point) I just prefer taking the predicates apart as far as possible so spec can tell me which one failed when it does.
@m3tti: I don't think there's any really good way. We looked into that a couple of years ago and ended up just using the Axis libraries directly.
SOAP is just awful :(
@seancorfield yeah it is i don`t like it either
Hi, is there a chance to forbid require, use, import etc. as symbols in the ns form? I just had weird bug because a library author wrote (ns foo (import (java.lang Whatever)) instead of :import. Works at the REPL for some reason, but aot compilation failed. Looks like a bug to me
@m3tti I do not know of a best way, but I was recently pleasantly surprised rolling a solution by hand using http-kit, (the new) clojure.data.xml and clojure.spec. Pleasantly surprised as in not ending up having to deal with tons of unwanted tooling or complexity and in that the solution is fairly concise and readable.
@fnil hi i was thinking about the same solution just posting a generated xml with clojure.data.xml. now i've the problem to get wse running. But i guess i'll do it the same way
@m3tti Cool. Where I did this we used the same methodology for a couple of integrations, but they were all fairly limited so I cannot speak for the scalability of the solution just yet. For now it seems to keep things in place quite nicely.
@fnil our xmls that we recieve are also quite limited with a limited amount of data. So i guess it is the best way to get the whole xml data via data.xml and doesn't hastle with java interoperability stuff
I am no longer able to build my project with leiningen because maven is telling me I don't have permission to access
. Is this a known issue?
@ibarrick You might want to do ls -las /releases/org/clojure/clojure-contrib/1.2.0-RC2/
and check the perms
good morning. i'm running benchmarks on some functions to try and optimize them and want to make sure i'm getting accurate results as they seem a bit odd...
i'm using criterium and i know you generally don't want to factor in the overhead of printing things, but then i'm always concerned when i see really fast numbers and/or ones that don't grow consistent with input that i'm not realizing lazy seqs. i made that mistake when i was first learning clojure and it's pretty obvious, but this case is a bit complicated so i could just use a sanity check
most of the work being done is by for
, which i understand to be lazy, but then i'm calling vec
on it immediately so my understanding is that should realize it. i'm also running the function many times on core.async channels and storing the output in a hashmap so i would think i'm doing it correctly. it just seems exceptionally fast (breaking 1ns for fairly complicated calculation) and also i'm a bit confused as to the results of playing around with optimizing it. for example using vector-of :short
rather than vanilla vectors is actually making it slower when there's nothing in my code i think could be boxing the numbers. so a bit suspicious and that's not even getting into the core.async issues
(the primary issue i'm seeing with core.async is calling thread
rather than just putting the function directly on channels is causing it to massively slow down. this could just be because the overhead doesn't justify that but, again, not sure)
i'm also seeing bizarre discrepancies between just calling time
and criterium's bench
that make no sense to me. the former at least shows an expected slowdown when i wrap it in`doall`. so quite confused by many aspects here...
@mpenet i'm not sure how much the code helps on its own. do you want to see some of the benchmarks that are making me second guess myself? or for starters how would you approach getting accurate numbers?
no need, I just wanted to have an overview. I am not sure why you're using core async tho, you put the result of the partial-diff call into a chan to take it on the next line
i originally was using doseq, but it wasn't playing nicely with core.async so i used a loop instead
and i am trying to refactor the core.async part to use a "fan-in, fan-out" pattern, but am a bit stuck on how to do it and maintain indexing of the output. it doesn't need to be sequentially returned, just stored under the correct keys
i have a rough version where i factor out the generator and consumer functions, but need to figure out how to propagate the idx to use as a key in the hash-map
and i suppose similar issue with using merge
to fan-in all the input channels: they each need to pass a separate idx parameter to partial-diff and then my consumer has to know which output its getting
trying to help with architecture https://clojurians.slack.com/archives/clojure/p1486481413018914
oh. thanks, but i was just answering some people's questions. i came on here to ask about benchmarking if you scroll up
Hmmm.... Why would (-> @session :handlers :debug)
return nil
but if I do (-> @session :handlers (keyword "debug"))
I get ClassCastException clojure.lang.PersistentArrayMap cannot be cast to java.lang.String
(get-in @session [:handlers (keyword "debug")])
works though. Is this something with threading I'm not aware of?
I guess I should use get-in then
For consistency I think I'll use get-in since I also use it in other places I'm getting the handlers from my session
State of Clojure 2016 results: http://blog.cognitect.com/blog/2017/1/31/state-of-clojure-2016-results
alexmiller: per suggestion from @seancorfield let's try this again the modern, threaded way: it would be interesting to know what peopke are using for cloud services, e.g. heroku, aws, gae, etc.
Agreed. An interesting question for next year. I’ll bet AWS leads the pack tho’, with Heroku and GCP aways behind. Maybe Joyent in there too?
i'm under the impression that gae isn't used much, and where it is it's roll your own due to lack of good libs.
what was done (if anything) to correct for the user confusion about the ranking in the survey?
@U0LGCREMU There’s a fair bit of work going in #google-cloud around making GAE / GCP much more Clojure-friendly.
I’m interested in the large number of people using Clojurescript and deploying to the browser. I wonder what front-end frameworks and libraries are popular.
sorry, didn’t see this till now (threads meh). I will make a note re cloud services, would be good to know
Thanks to all for responding (and sorry on the delay in posting)
to put my confusion about criterium/benchmarking from earlier more succinctly (and hopefully more lucidly), the numbers i'm getting are roughly as follows: criterium 800 µs, criterium with doall 800 µs, criterium with doall and pprint5s, time 800 ns, time with doall 1.2ms, time with doall and pprint 100ms. you can see how this would be a bit baffling... it almost seems like criterium could be the problem?
ashnur: i'm not sure if this is the kind of thing that'd help you out, but you made me remember i recently put together a library of some bit-twiddling functions since i needed to use a number of them for a project. some are a bit buggy, but i hope to continue to work on it going forward: https://github.com/Sophia-Gold/bitwise
in your call to quick-bench
be sure you reset any atoms in between, if that matters
i think it may be affecting running the full 60 samples since the hash-map gets so large
but quick-bench with doall seems the most accurate the more i think about it. a little over 1ms with a pretty intense input
my next question, a bit more substantial, was going to be why it's actually slower when i use vector-of
s with shorts rather than just vanilla vectors
also (sorry for all the questions) slower if i call async/thread
than just putting the function on channels, but that might just mean it isn't worth the overhead
from what i can see in the code, you have nothing that benefits from parallelism at all -- it is a sequential process, so starting a thread only adds overhead
that makes sense. there's a lot to optimize with my core.async code if i can figure out how to refactor it. pipelines were suggested. i was originally trying to use merge, but couldn't figure out how to keep track of the output
sophiago: would be a bit faster if you remove your unnecessary put!
and <!!
but i know you are determined to use async
well, i'm thinking more i need to figure out a way to keep track of the indices without looping through sequentially. ideally i'd like to generate all the function calls with thread
, use merge
to put them on one input channel, and have a separate consumer
hmm, and you're right...i just tested it and it's about exactly the same with or without the async code the way i'm doing it now. there's nothing about it that's inherently sequential though so i bet i could speed it up significantly if i could manage to refactor it to start all the calculations at once
although not all of those are concurrent. they increase exponentially. so that's three loops through with the last one being 3^4 = 81
i'm playing around now with keying them in the partial function so that i can just map them to threads in my generator and them merge them onto one channel
then maybe use a go-loop in the consumer to pull them off, store per order in the hash-map, and feed them back into the generator
@joshjones do you have time to give me your opinion on my attempt at refactoring that async code? it seems like i have the right idea, but i'm not sure how to go about cleaning up all the channels i create after the "fan in" part so it's throwing that comically named "ManyToManyChannel" error 😛
i was thinking i would benefit from something like the "fan-in, fan-out" pattern here: https://blog.golang.org/pipelines
Folks, don’t forget that using threads in messages can make it easier for others to have conversations so one or two people’s problems don’t overwhelm the room...
and, or, etc in clojure all treat nil and false as false and anything else as true, that definition of xor doesn't do that
@hiredman You're right, but you have to be real careful if you want thos semantics, for instance your function is not commutative
it depends, right, if you are doing clojure style logical operations, then 1 and true cannot be distinguished
@hiredman I think this additional param to and
fixed this: (fn [p q] (or (and p (not q) p) (and (not p) q)))
the ways in which you could say that xor definition are not commutative are the ways in which you could say that clojure's 'or' and 'and' are not commutative, because that is what it is built out of
@hiredman You're right doh. Though, both and
and or
always return an element from the input. Your original version did return true though, even though it was never given (b/c of the (not q)
)
Note that while the truth of (and p (not q) p)
and (and (not q) p)
are the same, the actual values may differ:
boot.user=> (let [p nil q true] (and p (not q) p))
nil
boot.user=> (let [p nil q true] (and (not q) p))
false
(which might matter if the downstream code used nil?
or some?
)
@seancorfield Ah good catch, so I got it luckyly right the first time 😄
commutativity as a property relies on some notion of sameness, or equality, and equality is very domain dependent
One day I got this crazy idea to host clojure atoms and core.async as an internal service, in place of a message queue, you’d just (foo/chan (foo/client “host”) “mychan")
and there’s your shared channel
Websockets in Aleph, with Manifolds?
that's pretty much what you describe
if you want something that plays really nice with core.async, I would look for something that allows you to place limits on queue size
I have, come to think of it, written 2 distributed job scheduling systems. they were very bad and worked just well enough that no one wanted to prioritize replacing them. I really hope next time I can use quartzite
I mean, I would almost certainly go for Quartz directly instead of with a library, but that is just me
we are currently re-implementing core.async channels on top of a distributed queue -- challenging so far in some respects, but looks promising
re:state of clojure, it would be interesting to know which cloud providers are preferred, e.g. heroku, aws, google app engine, etc.
Is anyone aware of a clojure couchbase client newer than https://github.com/otabat/couchbase-clj? We need one compatible with v 2.4 of the Java client
@nooga we’re actually implementing something like that (core.async channels as a service) internally; it’s been working well so far
@csm sounds interesting, are you actually using core.async inside? or did you just implement the interface?
core.async has a pretty opinionated stance on infinite queues (it doesn't have them) but I know (and have in a past life) used rabbit queues exactly like that
yeah, it’s core.async internally, basically with a simple RPC layer written with aleph and nippy
our use case was more one-to-one (you’re able to send a message if someone is receiving, otherwise you time out) so it’s not exactly a queue
in clojure spec, how do say: all vectors of three elements, where first elem = :vec2, second elem = float, third elem = float
@qqq Do you mean like (s/cat :type (partial = :vec2) :first float? :second float?)
“all vectors of three elements” sounds more like (s/every (s/tuple …))
eg: [[:vec2 1.0 2.0] …]
?
yes i think he means
(s/def ::qqq (s/coll-of (s/tuple #{:vec2} float? float?) :kind vector?))
(s/valid? ::qqq [[:vec2 3.2 3.0] [:vec2 9.9 1.1]])
;; remove :kind if outer collection doesn't need to be a vector
@qqqI mean valid data are of the form: [:vec2 1.0 1.0] [:vec2 3.0 5.0] [:vec2 3.1415926 1.414] etc ...
I think @joshjones has the closest solution