#clojure logs

2015-03-15

00:31jimrthyI may be looking at things the wrong way...has anyone used fnhouse with websockets?
04:05eli-sehi
04:15dysfunis there a builtin that is equivalent to (constantly nil) ?
04:15TEttinger#({}:P)
04:16TEttinger,(#({}:P))
04:16clojurebotnil
04:16TEttingeractually it can be shorter
04:16dysfunthat's just golfing it :)
04:16TEttinger,(#({}1))
04:16clojurebotnil
04:16opqdonuthere's one that's almost
04:16opqdonut,(#())
04:16clojurebot()
04:17dysfunthat won't take an argument
04:17opqdonutoh right and neither of these work with an argument
04:17dysfunyeah
04:17dysfunjust realised :)
04:17TEttinger,(#({}%&))
04:17clojurebotnil
04:17TEttingerthere you go
04:17TEttinger,(#({}%&) 1 2 3)
04:17clojurebotnil
04:18dysfunhow does that work?
04:18TEttingerplus, no alphanumerics!
04:18dysfun%& is & rest, right?
04:18TEttingerit takes an empty map {} and tries to get an element from it, where that element has the key equal to all arguments passed to the fn
04:18dysfunoh right, i see
04:18TEttingerif it doesn't get that key, nil!
04:18dysfunnice
04:19TEttinger%& is fun
04:19dysfuni think 'always' and 'never' would be useful
04:19dysfun(constantly true) and (constantly nil)
04:20TEttinger,(#(str %1 ": " (clojure.string/join ", " %&)) "Scruffy" "The Janitor" [:id 1])
04:20clojurebot"Scruffy: The Janitor, [:id 1]"
04:21TEttingerspecifically, %& is all args that don't already bind to a %1 or %2 etc.
04:28eli-seI'd just go with (constantly nil).
04:29TEttingerheh, eli-se with the injection of sanity
04:29TEttinger(inc eli-se)
04:29lazybot⇒ 1
04:38dysfunbecause that's already got a meaning in other languages. everything in clojure is a const (loosely, anyway...)
04:41amalloydysfun: that's not much of an argument. in haskell, const means the same thing as constantly in clojure
04:44dysfuntrue i suppose
04:44dysfunbut then haskell isn't exactly above changing the meanings of words also used in other languages
04:46dysfuni'm trying to think of an example where we do that in clojure
07:00justin_smithdysfun: for
07:03dysfunah yes
07:04dysfunthen again there's prior art for that usage, from CL
07:05dysfunah, protocols. in the real world they're the format of data. in clojure they're the format of behaviour
07:05justin_smithalso, agents
07:05dysfunlots of definitions of agent to pick from already :p
07:06justin_smithin the real world they are things that do things (usually on behalf of a user), in clojure they are mutable containers that serialize changes
07:06justin_smith(on behalf of a user, or as part of a simulation with an AI flavored actor model)
07:08dysfuni saw a really cool agent based simulation the other day simulating an evacuation of an office building. the 'humans' exhibited surprising behaviour
07:10dysfunhttps://www.youtube.com/watch?v=kHfHewzp5ls
07:11dysfunit can apparently do loads of humans in realtime on fairly mediocre hardware
07:20eli-sehi
07:20justin_smithhello
08:21thiagofmhi, what does the @ means in clojure/clojurescript?
08:22justin_smith,'@foo
08:22clojurebot(clojure.core/deref foo)
08:22justin_smithit means deref
08:24bcmIs there a lein template with cider nrepl baked in?
08:24justin_smithbcm: typically you don't want to embed cider in your project, only use it at dev time
08:24justin_smithit's better to add the dep to ~/.lein/profiles.clj
08:25bcmokay, but don't you need to do something like:
08:25bcm (nrepl/start-server :port 10101 :handler cider-nrepl-handler)
08:25justin_smithno, why would you need to do that?
08:26bcmThat's how I've been starting my repl, just before i start my server
08:26justin_smithif you have the cider plugin in your profile, you can just use "lein repl" to start up your repl
08:26justin_smithand then start your server from the repl
08:27justin_smithif you really want to, you can start nrepl from inside your app, but the cider-nrepl plugin should take care of making sure the middleware is there
08:27bcmso lein repl + cider plugin in ~/.lein/profiles.clj => cider-nrepl-handler ?
08:27justin_smithbcm: yes
08:27justin_smiththat's what the plugin does
08:27bcmoh i hope so
08:28bcmthanks justin_smith
08:29justin_smithnp
08:29bcmi have a second question: is enlive still the best way to do scraping?
08:29justin_smithit works pretty well for me
08:29bcmyeah I can use it too. just making sure noone made something amazing
10:28dysfunis there a channel for midje-related things?
11:40daniel`anyone using vim-eastwood?
11:40daniel`i get an error saying eastwood/lint__init not on classpath
11:54thiagofmthanks justin_smith
12:07paulswilliamsesqdysfun haven't seen one. I use midje a little bit but I probably won't be able to help.
12:09dysfunessentially i'm having difficulty matching nested data structures that contain records
12:10dysfuni've written a function that recursively turns records into maps and that's making my tests pass, but it's silly
12:10dysfunand when it prints out the expected and got they're character for character identical
12:11paulswilliamsesqbut it fails?
12:12dysfunwell, it did before i wrapped it with my utility
12:12dysfunhandily, thanks to the power of open source, i can show you
12:13paulswilliamsesqdysfun yeah, sure. I've done similar things. not with records.
12:13paulswilliamsesqgist?
12:13clojurebothttp://gist.github.com/
12:13dysfunhttps://github.com/jjl/qarma/blob/service-loader/t/qarma/system/loader_test.clj#L78 if you comment out the clal to derecordify, it fails with messages that identical things aren't identical
12:14dysfunof course they're not actually identical, because they're records
12:22paulswilliamsesqem.
12:22paulswilliamsesqso midje is establishing object equality which fails. I agree that wrapping the function on the left side isn't pleasent.
12:23dysfunyeah. i understand why it's doing that, but i can't find a different workaround
12:24dysfundo you think it warrants a bug report?
12:26paulswilliamsesqdysfun not sure about a bug report. Do you know marick? He's answered a few similar questions on twitter previously.
12:26paulswilliamsesqoh, I've just found https://groups.google.com/forum/#!forum/midje
12:26paulswilliamsesqdysfun seems pretty responsive
12:33dysfunhrm, i'll ask in a bit, thanks
12:40paulswilliamsesqdysfun the only thing I can think off without looking into the midje source code is to apply an inverse of your derecordify to the right hand side which would be slightly better.
13:03gruiHi! I've got a newbie question about Cider and Emacs and Clojure. I have this clojure file, and I do M-x cider-jack-in. After that I go to every line and hit C-x C-e to load every funciton into the repl. Is there some way to load a whole buffer, or a whole project (same thing?) into a Cider repl in Emacs? I tried selecting everything and then hitting C-x C-e, but it doesnt seem like it's working. Don't know for sure though, since as
13:03gruistated above I'm still very green with Lisp & Emacs... Thankful for any help!
13:04pdurbingrui: I highly recommend http://www.braveclojure.com/basic-emacs/
13:08gruipdurbin: so if I understand it right, I can do M-< C-Space M-> C-x C-e to load a whole buffer into cider? I don't understand the message returned, so I'll just assume it works...
13:15dysfunpaulswilliamsesq: aesthetically, perhaps. i'm not keen :/
13:17paulswilliamsesqdysfun I did say slightly ;-)
13:17paulswilliamsesqdysfun I'll look forward to responses on groups if you do post. I've just joined. I like the stubbing concept of Midje, I think it will be my goto test framework.
13:21pdurbingrui: I don't know. Hopefully someone here who knows emacs can help. I'm more of a vi guy.
13:24dysfunpaulswilliamsesq: i find it to be awfully convenient
13:25dysfunthere are a few cases i've found it to be pathological, but mostly it's great
13:25tomjackgrui: no, try e.g. C-c C-k
13:25tomjackif it's a normal clojure file defining a namespace
13:26tomjackalso, I'd be surprised (but not too surprised) if C-x C-e cares about the region
13:26tomjackI think it just always evaluates the 'last' expression
13:27tomjackactually I guess cider C-c C-k also works for just loading arbitrary code in a buffer
13:29paulswilliamsesqdysfun do you use the stubs long term, or just until you have working implementations to the stubbed functions? If that makes sense? Do you just use it for outside in dev, or long term isolation?
13:30dysfunactually i don't use all of that at present
13:30dysfuni meant midje was useful, not stubbing
13:31dysfunthere's a lot more i'm sure it can do for me, but i have to balance my time between so many things already
13:33paulswilliamsesqdysfun tell me about it. I'm sitting between the FP and good OO camps and have been strongly recommended to learn Smalltalk to help our Java developers and I'm still spending a lot of time learning Clojure.
13:38dysfunthe good oo camp? that's the one where they treat it as a functional language, right? ;)
13:39bbloomit's where you use just enough oo to bootstrap a functional abstraction :-P
13:41gfredericks~FP is more gooder than OOP
13:41clojurebotA nod, you know, is as good as a wink to a blind horse.
13:43dysfungfredericks: i know one thing: refs are better than locks
13:44gfredericks~refs are more gooder than locks
13:44clojurebotNo entiendo
13:44gfredericks~refs |are| more gooder than locks
13:44clojurebotc'est bon!
13:46gfredericks(if you state a claim using improper english you get to disparage that claim without having to have any reasons/arguments)
13:47gfredericks(free internet points!)
13:48tomjackgolf: (mapcat (fn [[k vs]] (for [v vs] [k v])))
13:48tomjack(that is a golf request, not a golf attempt)
13:49gfrederickswrong number of args (1) passed to mapcat?
13:49gfredericks(mapcat 1) also accomplishes that
13:49tomjackuh, isn't mapcat a transducer thingy now?
13:49tomjackwhere now = whenever 1.7 is released :)
13:49gfredericksprobably I forgot about transducers
13:49gfredericksand just eval'd it in my head
13:50gfredericksyep looks like it'd work
13:50tomjackI'm on 1.6 at the moment so I did the same thing :)
13:51tomjackI guess maybe that's the optimal number of points
13:54tomjackor one more: (for [[k vs] m v vs] [k v])
14:17tomjackI never noticed that :tag for a constant String def and :tag for a defn or a def fn which returns a String are the same
14:19Bronsatomjack: yeah.. :tag for fns refers to the return type of the fn rather than to the fn value itself
14:19tomjackgood thing you don't have to typehint fns
14:20Bronsawell.. this actually can be a problem sometimes, when your fns are more than just clojure.lang.AFns
14:21Bronsae.g. if your function is actually an IPersistentCollection or something like that
14:21Bronsa$source char-name-string
14:21lazybotchar-name-string is http://is.gd/JpGSXz
14:21tomjackhaha
14:21Bronsahere for example you have a hashmap tagged as String
14:22tomjackstatic types were just poisoning my brain
14:23BronsaI've never seen anybody actually complain about this issue though so I guess it doesn't really cause any problem in real code
14:23Bronsa(but it still bothers me)
14:24bbloomBronsa: hm, that is pretty interesting
14:25tomjackI'd guess the intersection of where it matters (usually non-Clojure Java APIs?) and where it happens is small
14:25tomjackand you can always use a local hint :)
14:25bbloomseems like objects that are both collections and functions are a theoretical problem more generally
14:26bbloomlike in scala, the fact that sets are invariant b/c they are both functions and collections
14:27Bronsabbloom: I saw a note by Rich about this issue in some confluence page written years ago. I guess there's no interest/it's too late to change how type hints works now
14:27bbloomi wonder if you could side step the problem by interpreting callable objects in terms of an implicit conversion to a function object
14:27tomjackI was going to suggest that
14:28bbloomsurely ambrosebs has some insight in to this whole situation :-P
14:28tomjackimplicitly transport along an equivalence to a container, then take the second projection which is a function
14:49paulswilliamsesqdysfun ;-)
14:58ambrosebssure it makes sense, I modeled type hint propagation as part of my latest paper
14:58ambrosebsin the appendix though, will dig it out
15:01ambrosebsbbloom: my opinion is that type hints are just hints and shouldn't be taken seriously. I'm perfectly fine with the current behaviour.
15:01bbloomheh. "shouldn't be taken seriously" is an interesting way to put it
15:02ambrosebsit's in the name
15:02ambrosebs:)
15:10ambrosebshere's my model of type hints
15:10ambrosebsfigure 6 http://frenchy64.github.io/doc/hint.pdf
15:10ambrosebsTA-Local is the normal behaviour you'd expect
15:10ambrosebsTA-AppLocal is the funky one
15:13ambrosebsthe question I'm interested in is "what do type hints tell you", which is why I concluded they shouldn't be taken seriously
15:13ambrosebsand I specifically mean in terms of verification
15:13ambrosebsthey are seriously cool in their own right
15:14ambrosebspeople seem to think they make good documentation or tell you something about your program.
15:25justin_smithambrosebs: removing runtime reflection is kind of nice though?
15:26ambrosebsjustin_smith: of course!
15:26ambrosebsthat's why they're cool
15:26ambrosebsnot because they give you insight about what a particular function takes, for example
15:29justin_smithyeah, they do only one very small part of what people think of as "typing" in code
15:30Bronsaambrosebs: they kind of enforce input types in some cases though
15:30ambrosebsBronsa: exactly :)
15:30justin_smithBronsa: with primitives?
15:31ambrosebsBronsa: assume nothing :P
15:31Bronsajustin_smith: yeah
15:49gfredericksambrosebs: does core.typed have anything for specifying the type of metadata?
15:50ambrosebsgfredericks: no
15:50ambrosebsgfredericks: something I intentionally overlooked, could be added
15:50gfredericksif it did you could use that to get good old-fashioned nominal typing, right?
15:50gfrederickswith :type metadata or something
15:50ambrosebswell it would be the same as a :type entry in a HMap
15:51gfredericksright
15:51ambrosebswhich you can do lots of things with
15:51gfrederickskind of a dumb question I guess
15:52ambrosebsnot sure what you mean by nominal typing since metadata is a structural type
15:52gfredericksmeant the same thing as what you'd get with a normal :type key
15:52ambrosebsyes ok
15:52ambrosebscorrect
15:52ambrosebswould be cool to have
16:16paulswilliamsesqHi, is there a concise way of extracting a seq of titles from [{:title "the shining" :age "18} {:age "pg" :title "Jaws"}] - i.e. I want ("the shining" "Jaws") ?
16:17voytechHi did You heard about postwalk ?
16:17ambrosebspaulswilliamsesq: (map :title yourseq)
16:18mpenetanyone knows how to run the cljs test in core.async ?
16:18paulswilliamsesqambrosebs thank you - I was using map but writing my own anon function to extract the title within it!
16:18ambrosebspaulswilliamsesq: also valid
16:18paulswilliamsesqambrosebs yeah, it works but was verbose
16:22voytechI had some problems with with-redefs . What I'm trying to achieve is to redefine some var from other namespace temporary, then call code which uses this var somewhere internally in multiple places, But my function is not being called in place of original one ? Is with-redef ony for binding in lexical scope ?
16:22ambrosebs,(doc with-redefs)
16:22clojurebot"([bindings & body]); binding => var-symbol temp-value-expr Temporarily redefines Vars while executing the body. The temp-value-exprs will be evaluated and each resulting value will replace in parallel the root value of its Var. After the body is executed, the root values of all the Vars will be set back to their old values. These temporary changes will be visible in all threads. Useful for mockin...
16:23ambrosebs,(source with-redefs)
16:23clojurebotSource not found\n
16:23ambrosebsvoytech: looks like it's a big hammer and globally redefines vars.
16:23ambrosebsvoytech: is the code your calling returning a lazy sequence?
16:24ambrosebsperhaps you need to realise it while the redefs are in effect
16:25voytechnope not lazy-seq
16:25ambrosebscode?
16:27voytechambrosebs: https://gist.github.com/voytech/3bf374bcf81a023184b1
16:29ambrosebswhat does deftask do?
16:29ambrosebslooks like you're just returning a function
16:30voytechyes
16:30ambrosebsmaybe you need an extra (fn [& body] (with-redefs [...] (apply (comp ...) body)
16:31voytechAhh so when I'm returning function
16:31voytechwhen it will be called
16:31voytechit will be out of the scope of redef
16:31ambrosebsyes
16:31voytechahhhh!
16:32voytechthank You for your quick eye then :)
16:33ambrosebsnp
17:07daniel`anyone using vim-eastwood? i get an error could not locate eastwood/lint__init.class
17:07daniel`have the dependency in my lein profile
17:11daniel`nevermind, got it working
17:11daniel`problem with my lein profiles data
17:12daniel`night folks
17:23MisatanaFor those who've submitted Clojure issues to JIRA before, do the {code:none} … {code} blocks denoted at https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=advanced work for denoting code blocks in issues' descriptions?
17:28bbloomMisatana: you can edit descriptions after you submit tickets, so just give it a try
17:39Misatanabbloom: I actually haven't been able to edit any of my issues from the past so far, so I'm a little leery of trying formatting before making sure. https://confluence.atlassian.com/display/JIRA/Editing+an+Issue suggests that I should be seeing an Edit button, but it's not showing up for me; pressing the E key doesn't work either.
17:40bbloomMisatana: worst case scenario: you put an updated description in to a comment & ask somebody to fix the ticket for you
17:46Misatanabbloom: All right; thanks.
17:47BronsaMisatana: {code} .. {code} blocks work fine, also you can preview the description before submitting a ticket
17:48MisatanaBronsa: Aha, I see. I hadn't realized that that little icon below was a preview button. Thanks a lot!
17:51Guest70851Hey there. I am looking to start learning Clojure and have been looking at some books. Judging by Amazon ratings, it seems that O'Reilly's "Clojure Programming" by Emerick, Carper and Grand is held in the highest regard. The book is two years old though, so my question is: is "Clojure Programming" still relevant in 2015? Or is it recommended in general? (I have been programming for a year, mostly in imperative languages but a lit
17:53justin_smithGuest70851: yeah, there are new features since then, but nothing it describes has changed iirc
17:53justin_smith~books
17:53clojurebotbooks is http://clojurebook.com/ http://joyofclojure.com/
17:54scottjGuest70851: fyi irc has a message length limit
18:00raspasovGuest70851: I would say yes, without having read it all; I have the book though, and any time I've gone to consult it the information has been top notch
18:03Guest70851Thank's justin_smith and raspasov for your answers
18:04justin_smithGuest70851: that book, JoC, and this IRC channel are where I learned most of what I know about clojure
18:05Guest70851Sweet. I read that JoC is a bit harder to read for a Clojure beginner, so I guess I'll wait with that one.
19:22wei_is there a way to do a “for” form with an index?
19:24havenwoodwei_: I don't know what you mean, but it makes me think of #each_with_index.
19:24gfredericks(for [[x i] (map vector coll (range))] ...)
19:24havenwoodoh, sorry, wrong channel :(
19:24gfredericks(for [[i x] (map-indexed vector coll)] ...)
19:25gfrederickshavenwood: hah!
19:25gfredericksthat's the first time I've seen "wrong channel" when actually answering a question
19:26wei_thanks gfredericks. I guess map_indexed by itself would work, but it just has different semantics
19:26wei_havenwood: i thought i had posted in the wrong channel for a sec :)
19:26havenwoodwei_: gfredericks: #crystal-lang is just too close to #clojure alphabetically.
19:27gfrederickswei_: different semantics or different syntax?
19:27wei_ah, just syntax. at first I thought “for” was eager
19:35skeuomorfjustin_smith: Hmm, JoC website doesn't work without the www prefix, I tweeted Michael Fogus but I think it should be changed here meanwhile?
19:35skeuomorf!ops
19:55rs0datomic uses Fressian internally, right?
19:56rs0in the storage layer?
20:00gfredericksI believe so
20:02rs0ok. i've been looking at Fressian a lot lately and it seems like there's been no work on it at all after its initial release
20:02bbloomrs0: i think that might be b/c it's *done*
20:03rs0bbloom: it's... not
20:03rs0bbloom: clojure collection types don't even round trip through data.fressian, with the exception of maps
20:03bbloomrs0: *done* ... for the purposes of datomic
20:03bbloomalthough they surely have an internal fork
20:03rs0bbloom: that's what i'm thinking
20:04bbloomrs0: do you need binary storage? or are you looking for a transport data format better than json?
20:04rs0bbloom: https://github.com/rschmitt/dynamic-object
20:04bbloomb/c transit fits the latter role
20:05rs0bbloom: i'm aware of transit, but i want to add binary serialization to dynamic-object
20:05bbloomrs0: use transit w/ messagepack
20:06bbloom(assuming they actually implemetned that, they said they were going to)
20:06rs0bbloom: i thought that Transit wasn't even stable yet
20:06rs0bbloom: they specifically said not to persist anything durably in Transit, in case it changes later
20:07bbloomrs0: ah,yes, i remember that. & see it in the readme at https://github.com/cognitect/transit-format#implementations
20:07rs0that's one reason i didn't look extremely closely at Transit; Fressian appears more mature
20:07rs0another reason is that Fressian actually has a really clean Java implementation. the Transit library looks really GoF to me
20:08bbloomyou're more likely to get details about stability, compat promises, etc from the mailing lists
20:09rs0which ones should i look at?
20:10bbloomthe main clojure users list is probably the place to start
20:10rs0k
21:00sg2002Hey guys. Have a question about debugging. Is there a solution that allows you to store function args every time it's called? I've been using spyscope, but printing data is not as useful in my case. I'd rather store them in some var instead. Seems kind of an obvious idea and an easy thing to implement myself, so there has to be a working implementation already.
22:05gfrederickssg2002: (defn store-args! [some-var] (alter-var-root some-var (fn [orig] (fn [& args] (alter-meta! some-var update-in [:calls] (fnil conj []) args) (apply orig args)))))
22:06gfredericksI'd probably pull in robert.hooke for a more slicker impl
22:20gfredericksthis kind of makes me want to add to my repl utilities something that will instrument every function in a namespace with a hooke that stashes the args anytime an exception is thrown
22:21gfrederickswhich is a bit leaky now that I think about it
22:21gfredericksbut probably worth it for just repl stuff
22:49sg2002gfredericks: Thanks. Using metadata for this is a great idea.
22:51gfredericksnp