This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-30
Channels
- # admin-announcements (19)
- # announcements (4)
- # beginners (22)
- # boot (76)
- # cider (92)
- # clojure (235)
- # clojure-berlin (3)
- # clojure-germany (1)
- # clojure-italy (8)
- # clojure-japan (18)
- # clojure-russia (26)
- # clojure-sg (1)
- # clojure-uk (25)
- # clojurescript (55)
- # code-reviews (7)
- # core-async (53)
- # datomic (13)
- # euroclojure (63)
- # jobs (39)
- # ldnclj (45)
- # off-topic (9)
- # om (7)
- # onyx (6)
- # reading-clojure (1)
- # reagent (5)
- # yada (22)
hello guys, I'm looking up for a Clojure function that does something like this: (FN [[1 2 3] [:a 😛 :c]]) and returns -> ([1 :a] [1 :b] [1 :c] [2 :a] [2 :b] [2 :c] [3 :a] [3 :b] [3 :c])
it's like having a (for), but with a dynamic number of iterables in the middle
there a function in core to do that?
would this be helpful https://github.com/clojure/math.combinatorics/ ?
; CARTESIAN PRODUCT
; all the ways to take one item from each passed-in sequence
=> (combo/cartesian-product [1 2] [3 4])
((1 3) (1 4) (2 3) (2 4))
yes it is, although I was hoping to find that on core (since it's kind of provided with for), also I'm using ClojureScript, so I may end up just copying part of that source
thanks
just fyi: just copied the cartesian-product and it worked jsut fine, it doesn't depends on any other function there
@wilkerlucio: sometimes juxt, which is part of the standard library, comes in handy for similar situations or if you can change your code to make it work https://clojuredocs.org/clojure.core/juxt
@meow: hi, I got curious now, how would you use juxt to generate a cartesian product of a list of lists?
@wilkerlucio: I'm half asleep so I'm just going to wave a white flag and surrender because I remember needing a Cartesian product a couple of weeks ago and instead my situation lent itself to some other approach that I thought used juxt but I just looked through my sandbox of code and can't find anything so I'm not sure what I'm half-remembering. Anyhow, juxt is just a cool function but cartesian-product is obviously a good match when you need something like, you know, a cartesian product... 😉
hehe, yeah. I agree that juxt is great, I always try to find uses for it as well, but I end up using it mostly when sorting/grouping things
on my current case I really need a cartesian product
the first time I saw juxt was somebody (can't remember who) that used it to calc the neighbors of a cell in a grid for conway's game of life:
(defn neighbors [[x y]]
(map vector ((juxt inc inc identity dec dec dec identity inc) x)
((juxt identity inc inc inc identity dec dec dec) y)))
I thought that was pretty clever and so juxt stuck with me.And now I'm going to go dream about core.async channels and what's the ideal set of them for capturing all the events that take place in a cljs app...
I’m a bit confused about defrecord methods. [This](https://github.com/apa512/clj-rethinkdb/blob/1792b7ca90fe0b5396329c36cfa1c53429b2fa6c/src/rethinkdb/core.clj#L37-L41) defrecord has a close
method, which calls core/close
. I assumed that calling (.close connection)
would be equivalent to (core/close connection)
but it isn’t. What am I calling when I do .close
?
.close
returns nil
, while core/close
returns :closed
@jonas: sorry I don’t understand?
ah yes, but isn’t .close
just calling this function?
I think this might be related to defrecords creating functions for their implemented method names
Is it possible that because Closable is a void method, that it would return nil even if something inside it returned a value?
I’m hoping the answer is yes or I need to question everything I know
@danielcompton: I am guessing but probably something to do with method dispatch. It’s calling the Closeable close method rather than the core/close function? (function overloading?)
yeah, that’s pretty much it
any idea why the new lein doesn't run tests for the code-maat project guys?
@donaldball @noisesmith thanks for your insights last night on my form keyword params question
I also discovered that I've been using clojure.walk/keywordize-keys
I think the main reason keywords are used (rather than strings as map keys) is for ease of extraction (they satisfy IFn) whereas strings don't, I wish sometimes they would
Hmm... Given two vecs (def x [1 5 4 2 1 4]) (def choices [9 7 2 3])
I want to return the first item from choices
that I find in x
(`found`) and the remainder of x
with found
removed (only one removed if multiple in x
). x
will always contain at least one of choices
, order of x
never matters, all vecs are small (less than 20 items), speed matters a bit. So far I've only come up with loop
-based solutions. Any neat ideas?
There is a trick where you let choices be a set, probably someting a la (first (filter #{ 9 7 2 3} x)
@ska: if the ordering of x does not matter, it may be more efficient to store as a frequency count map instead (something you get from (def y (frequencies x)). Then you can do (some #(if (pos? (get y % 0) (update-in y [%] dec))) choices)
@tcrayford: Actually I had another question for you after your talk - do you use definline at all?
@tcrayford: I have some namespaces which pretty much just wrap Java APIs, so most of the fns simply wrap one interop call. It seems like definline should work well there since you save a stack frame and I suspect the bytecode for an interop call is smaller.
I have problems with a particular setup of core.async channels. Here's a minimum example showing the intent and exposing the problem: https://www.refheap.com/104584 My intent is being able to send a message through one channel and wait until arbitrary number of messages come back from another channel - for this I'm using a blocking version of take operation (<!! - here it's actually alts!! to handle the timeout). What I observe is only the first message comes out of 'result' channel - and only on first try after running the top level go-loop. After that what I get are only timeouts. I suspect I'm doing something terribly wrong.
it should be loop instead of go-loop so that it will be blocking and function will terminate only after receiving messages or timeout
... and this way it seems to work. heh, nevermind then, the problem has to be somewhere else
ok, here's the example closer to the problem I'm experiencing along with the output of example repl session: https://www.refheap.com/104589
Ok - the APIs I wrap are pretty huge. I wrap them partly for prettiness, but mostly to hide the type hints.
I'm only accepting some messages from the source channel ignoring others. First 2-3 invocations work alright - after that, timeouts happen
Yeah, I’m planning to try it. I actually AOT everything so counting should be simple using ASM.
you can figure it out by http://stackoverflow.com/questions/10486375/print-all-jvm-flags
FreqInlineSize is only for "hot" codepaths, there are other flags for less hot paths
see also InlineFrequencyCount
, MaxInlineSize
, MaxRecursiveInlineLevel
, InlineSmallCode
, InlineFrequencyRatio
, InlineThrowCount
, InlineThrowMaxSize
(or just search http://stas-blogspot.blogspot.de/2011/07/most-complete-list-of-xx-options-for.html for "Inline")
as always, feel free to reach out to me. <mailto:[email protected]|[email protected]> if you have anything sensitive or whatever
I actually have to target JDK6, but I can use a later one for running benchmarks once I get that figured out.
perf is trickier for a product like cursive compared to Yeller - Yeller has like 3 code paths where it needs to be really really fast etc, but cursive needs to be fast everywhere
The main problem is that the infrastructure is huge, opaque and very complex, especially the indexing stuff.
Right. I think JetBrains tend to go for quite coarse grained perf work (i.e. the IDE usually takes from 3-4 seconds to start up), but they must have to optimise some hot(ter) paths too. I’ll ask them.
Hi everyone. Is there a nice way to return only the first value from a list-comprehension? I do not want to (first) after i have the results, i would like to break the execution after :when returns the first element.
@thomasdeutsch: not that I know of. But laziness should save you here!
@thomasdeutsch: probably won't work, as clojure chunks its sequences, so it'll probably calculate the 32 first values
Thanks for the info, i will look into it.
@thomasdeutsch: are you concerend about performance, side effects, or something else?
as far as I know there's currently no easy way to prevent eager pre-loading of elements of a lazy seq
it would be very useful actually, when the computation is expensive or has other side effects
why does it need to be a list-comprehension?
reduce with reduced, or a loop-recur, or take transducer all offer early exit opportunities
@alexmiller: true, but there are scenarios where you don't want to change the code
e.g. if you're testing a function built on for
or map
, and you only want to evaluate the first element
map chunks, but I don't think for does?
nah, I'm wrong, it does
I’ve been looking at the source code of the Pepa app that 2 Moritzes presented at EuroClojure and noticed they made config a component https://github.com/bevuta/pepa/blob/master/src/pepa/config.clj Any of you know what are the benefits of doing that? The most common way is to pass different parts of a map to initialise components and not make the config itself a component.
I always assumed that map
and for
are pretty much equivalent for simple cases
filtering the channel fixed the problem: https://www.refheap.com/104594 . However I'm still not sure why the ignored messages clog up the channel pipeline - code docs for mult
state that messages sent when there's no tap are discarded
@annapawlicka: it's unclear to me as well. I'd say the equivalent holds true for componetizing logging.
@pyr, I agree
I'd say, use components when you must, not when you can
it does seem like an overkill, but maybe i’m just not seeing something
(yeller has an admin endpoint available on each server that dumps a json blob of all the components)
(then I just use one of the chrome json prettifier plugins to view it in more depth)
pesterhazy: yeah, the primary loop for a single-source is about the same (although for does a lot more work in setup to deal with all the special clauses). regarding the original question, the takeaway is really that if you want to control the rate of evaluation of a source, lazy seqs and seq ops do not give you fine-grained control. there are better options (esp now with transducers) if that is what you need.
good point @tcrayford
@annapawlicka: I don’t recomment making config a component because this prevents the composition of the system to depend on configuration. In other words you cannot create components selectively.
@annapawlicka: additionally configuration does not carry state and thus is not required to be a component.
yeah, that was my reasoning as well
@tcrayford: it's an interesting property, but not one you need components for
@pyr: for sure. I don't actually use component at all (yeller predates that library), just saying it makes that thing trivial.
I try to go with something like lein-env
and a global set of immutable values. They’re used only at system construction time and passed into the component where necessary
@goodwind89: Neat idea with the frequencies. Will consider that.
@tcrayford: nothing prevents you from that. Injecting a „configuration component“ into your components is a different story.
@annapawlicka: another point, when you look at https://github.com/bevuta/pepa/blob/master/src/pepa/zeroconf.clj#L32 you see that this component has some hidden coupling to the two config keys.
I like my stuff explicit.
if I open 2/3 repls on different projects with 8GB of Ram I already start to get out of memory errrors
each of them take > 700 MB is that normal?
@andrea.crotti: you can assign each jvm less ram of course
annapawlicka: if you haven't looked at immuconf, I like it a lot and have used a variant of it on some internal projects https://github.com/levand/immuconf
ohhh, haven’t seen that, thx!
it's not as well known as it should be imho
@pesterhazy: but that's the hard limit for that repl I guess right?
so if the project said it needed X and I give less it might explode after?
@annapawlicka: I cover it some in Clojure Applied
@alexmiller: that looks like exactly what I should switch yeller to. Thanks 😄
oh yeah, edn maps ftw over that
yeah, just a case of 13k lines of app code and basically no time. Lots of things like that in Yeller these days
oh, understood
hey my main project is 60k lines of Java and 20k lines of Clojure ;)
(that's Clojure itself of course :) )
nice thing about yeller there: there is one developer, so like, if I wanna change something large, there's no discussion or anything, I just do it
I should get that book, though I'll have to wait for the paper version.
I also like yaml, because it reminds me of ansible
hi all, i have a beginner question: what does it mean to apply a keyword to a something, which is not a map? in the documentation (http://clojure.org/data_structures#toc8) there is a statement, that the keyword accepts a map as a parameter. but somehow things like this work: (:bla "blups") => nil (:bla \b) => nil I assume this "unwraps" into smth like (get obj keyword), but have no idea how to find it, neither in CLJ source, nor in the documentation.
pesterhazy: print version will be out in late August/early Sept probably
shinych: keywords actually implement IFn, so they are actual functions
shinych: yes, just so - keywords can be invoked as a function with an associative data structure and it turns into a get on the data structure with the keyword itself
@alexmiller: excellent, should make for great beach reading
shinych: get itself is similarly tolerant about receiving non-associative inputs - there is actually a jira to change this behavior
Stuart Sierra and I have been talking to Rich about that for a long time. I don't think we've convinced him yet. :)
@alexmiller: thanks! Can you pls give me a hint where can I find the special handling of keywords in CLJ source code? Since it is neither a function nor a macro I have no idea even where to start to look...
Keyword.java is the keyword implementation
@shinych: see https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java#L130-L141
oh, @alexmiller got there first
Keyword implements IFn and the invoke() method is what will get called
similarly, maps sets and vectors also implement IFn as an associative lookup
@alexmiller: I had a case like that in my talk: https://vimeo.com/132088218 from about 28:55 here
@tcrayford: the question was indeed inspired by your talk, I've been there
@alexmiller: got a 5x perf speedup on a thing after fixing the typo
I think the biggest question is how much existing code relies on the behavior for reals and would be broken
I have not tried to evaluate that
should be easy to check by making Keyword raise an exception if called with a non PersistentHashMap argument
as a test, I mean
dissoc-in is really missing in core https://github.com/amalloy/useful/blob/develop/src/flatland/useful/map.clj#L81
you have assoc-in update-in but no dissoc-in
@narkisr: There is an inactive JIRA card for this. You should see if you can re-visit it: http://dev.clojure.org/jira/browse/CLJ-1063
Ill take a look thanks
the problem as I recall is that it's unclear if it should remove empty paths along the way or not
What do you mean by empty paths?
Oh never mind I think I figured what you meant
There is a dissoc-in
in core.incubator as well I think.
Yeah the issue mentions it, since I already use incubator is not an issue for me, many folks won't find it tough
@andrewhr: Not really. It was created a long time ago but hasn't had a clearly-defined purpose or a regular maintainer.
Clojure 1.7.0 is now available http://blog.cognitect.com/blog/2015/6/30/clojure-17
@annapawlicka: The only reason I can think of for making "Config" a component is to incorporate loading of config files into the Lifecycle/start process. I usually load configuration as a separate step before constructing the system.
In other URL-related news, Clojure turns Seventeen!
Congrats to the core team, a lot of hard, thoughtful work went into 1.7
I am mildly amused that Rich Hickey is not listed among the contributors to 1.7
any pointer to transducer? I'd like to learn about it
@stuartsierra: thanks. I usually load config file at the very beginning too. Config is static and I always use components for things that have some sort of a state.
sth practical, I'm not much into academic stuff
@stuartsierra: We went the route of a config component in our system. In our case, we have so many ways of building the system graph based on lots of factors (including testing vs. production), and we define what's acceptable in the configuration in terms of meta-data on the components ... a Prismatic Schema of what that component expects to find in the merged configuration. So we need to know what the components are so we can build the combined configuration Schema.
donaldball: he didn't contribute any patches (just commits to master :)
Making that configuration map a component was a better alternative than scattering the startup logic around to widely, or having to define components in terms of a callback that gets the configuration, rather than a component that has the configuration "injected".
goodwind89: well http://clojure.org/transducers is one place to start with links to other things
@alexmiller: I can never seem to find the link to the full release notes ... would be nice if that was linked to from the announcement.
@alexmiller: Congratulations on the release!
Congratulation! It's a pity we didn't properly celebrate the release in Barcelona.
hlship: it's linked in the first paragraph
Well that's egg on my face. Very subtle color difference for the link ... and I did look first before I complained here. Not sure how I missed it though.
well you've probably visited it before so it's the visited color
it's ok though, I know no one reads anything http://tech.puredanger.com/2007/07/11/miller-principle/ ;)
alexmiller: if only I had read that blog post
Congrats on the release! Time to port one of my libs from cljx to reader conditionals!
abtv: I'd like to get a core.async release out at some point. it's supported transducers since last fall so that's not an issue.
It's getting released asynchronously. 😛
alexmiller, it's pretty unusual to see a mature library with an alpha status. There were at least two presentations about core.async in 2013. So long ago! Maybe you should mark it as beta or release candidate? Just for newcomers 😀 Yes, I know that alpha status for Clojure project is sometimes release candidate in projects of other languages. But nevertheless 😌
it is quite interesting that transducers is in a final release, given that it was made in response to not wanting to redo everything for core.async, and core.async is still alpha
i guess now that transducers are baked, the fine folks who work on this can pay attention to core.async again
that said, it doesn’t really matter from a practical standpoint. it works just fine!
Alpha is just a state of mind
@arrdem: don't I say enough dumb things already?
@alexmiller: you're a saint
@arrdem: I'll let my wife know