#clojure logs

2015-03-08

14:09noncom|2does clojure support multilevel destructuring?
14:10noncom|2like (defn f [x {:keys [m {:keys [n] :as A}] :as B} ) ?
14:10justin_smith,(let [[[[a]]] [[[42 43 44]]]] a)
14:10clojurebot42
14:10noncom|2hmmm
14:10justin_smithnested :keys isn't going to work like that
14:10noncom|2that's what..
14:11noncom|2sad..
14:11justin_smith,(let [{{n :n} :m} {:m {:n 42}}] n)
14:11clojurebot42
14:11justin_smithyou just can't use :keys that way
14:12justin_smiththe destructuring still works nested
14:12justin_smith:keys tells the destructuring that everything in the vector is a keyword
14:12justin_smithputting a map inside makes no sense
14:13noncom|2yes, i know what you mean
14:13justin_smith,(let [{{:keys [n]} :m} {:m {:n 42}}] n)
14:14clojurebot42
14:14justin_smitha compromise
14:16noncom|2heh :)
14:16justin_smithto me, :keys isn't even worth it until you have more than two items from the same map
14:26turtl3’allo all
14:26gfrederickshellooo
14:26turtl3newb to core.typed & confused
14:26justin_smith,(rest "hello")
14:26clojurebot(\e \l \l \o)
14:26gfredericksjustin_smith: I kind of like it just for calling out the key & the name being the same
14:27gfredericks~newb to confused |would be| not the worst band name
14:27clojurebotAck. Ack.
14:27turtl3Can’t get typed to grok expressions using partition with strings, e.g. (partition 2 (String. "ABCD"))
14:27turtl3gfredericks: hah
14:27gfredericksturtl3: you want it to infer a seq of seqs of chars?
14:28turtl3gfredericks: yep, can’t seem to make “String” fit “(t/Coll a)”
14:28gfredericksyeah it's not really a collection
14:29gfredericksdoes partition require a t/Coll?
14:29gfredericksdoes (partition 2 (seq (String. "ABCD"))) typecheck the way you want?
14:29turtl3indeed. Domains:
14:29turtl3 java.lang.Number (t/Coll a)
14:29turtl3Arguments:
14:29turtl3 (t/Val 2) String
14:29justin_smithturtl3: why (String. "ABCD") instead of "ABCD" ?
14:30turtl3justin_smith: doesn’t matter much in this case, t/Val vs String. String is closer to my “real” code
14:30justin_smithI guess what I don't get here is that (partition 2 "ABCD") is exactly the same as (parititon 2 (seq (String. "ABCD")))
14:30justin_smithand I don't understand when you would want the latter
14:31gfredericksbecause type systems
14:31justin_smithOK.
14:31gfredericksstatic type checkers, more precisely
14:32gfredericksthe more precise cause of this exact thing is that partition is not accurately typed
14:32turtl3of couse seq was the first tool i pulled out, but ASeq != Coll
14:32gfrederickswhich may be due to laziness or maybe some limitation of the type system I don't know about
14:32noncom|2how do i change space between lines in lighttable?
14:32gfredericksI expect Seqable is closer than t/Coll
14:32noncom|2does anyone use lighttable for real dev?
14:33turtl3gfredericks: and i thought it was just me
14:33gfredericksor whatever is core.typed's terminology for things that clojure.core/seq accepts
14:34turtl3gfredericks: actually i suspect it is String weirdness
14:34turtl3https://github.com/clojure/core.typed/wiki/Strings
14:35turtl3some discussion there i don’t understand about Strings not be Seqable
14:35gfredericksSeqable is an interface
14:35gfredericks,'clojure.lang.Seqable
14:35clojurebotclojure.lang.Seqable
14:35gfredericksanything that implements it can be converted to a seq
14:36justin_smithgfredericks: that was a keyword, not an interface
14:36justin_smith,clojure.lang.Seqable
14:36clojurebotclojure.lang.Seqable
14:36gfrederickshey I do what I want
14:36justin_smitherr, symbol I mean
14:36justin_smithheh
14:36gfredericksanyhow there are a few hard-coded extra things that can be converted to seqs as well, all of them native JVM types
14:36gfredericksand on the JVM you can't take a builtin or 3rd-party type and have it implement your interface
14:36gfrederickswhich is the reason they are hard-coded extras
14:37gfredericksstrings, arrays, other generic jvm collections
14:37gfredericks,(seq "foo")
14:37clojurebot(\f \o \o)
14:37gfredericksit's talking about the reason ^that works
14:39turtl3gfredericks: the result of a "(seq x)" on such a thing seems not to be compatible t/Coll. but making a copy with e.g. vec sidesteps the problem, but that seems so wrong
14:40gfredericksyou could write a ^:no-check helper function :/
14:40gfredericks(t/ann string-seq [String -> (t/Seq Char)]) (defn ^:no-check string-seq [s] (seq s))
14:40gfredericks;; or whatever
14:40gfredericksthis is my experience with core.typed
14:41gfredericksmost of the times I try to do something with it it ends with ambrose asking me to file a bug
14:41turtl3i guess that’s what they mean when they say it’s not ready for prime time
14:41gfrederickswell I mean the thing you're describing isn't going to prevent you from doing something
14:41gfredericksit just feels gross
14:41gfredericksbut sometimes having the type checker around to give you a thumbs up is worth feeling gross about a few bits
14:42turtl3gfredericks: perhaps. i may have chosen an unfortunate place to start
14:42gfredericksthere's generally a tension between core.typed and common clojure style
14:43gfrederickswhich might be unavoidable
14:43justin_smith,(map #(.charAt "hello" %) (range (count "hello")))
14:43clojurebot(\h \e \l \l \o)
14:44gfredericksCore Dot Typed: You Are Going To Have To Write Your Code A Bit Different And Some Things Won't Be Checkable At All™
14:44justin_smithdunno if that is actually helpful
14:44turtl3justin_smith: thanks, another way of building a copy
14:45justin_smithright
14:45justin_smithdoes the seq version not build a copy?
14:45AeroNotixhttps://gist.github.com/AeroNotix/1d71a81b03e08e8c5f0e the WebSocketClient constructor here is being called with an array, right? Or am I just misunderstanding the error?
14:46gfredericksjustin_smith: nothing that partition doesn't already do
14:46justin_smithgotcha
14:47AeroNotixoh wait, I was returning the wrong type in a ctor.
14:47gfredericksturtl3: I would often find myself writing copies of certain functions with more specific types
14:47gfredericksso e.g. another option is to write your own partition
14:50turtl3gfredericks: i don’t think i’m that hellbent on type checking today. this started out with a colleague asking for some documentation on the types a few functions were written for. i figured, what the heck, i might as well document it in a way that a compiler can understand
14:50gfredericksACK
14:50justin_smithturtl3: if it's mostly about argument / return value types I find prismatic/schema to be a nice option
14:51justin_smithit's got a different rationale, but it also allows type annotations (instead of verifying at compile time, it is optionally tested on runtime input)
14:53turtl3justin_smith: that’s interesting, i’ll take a look
14:58AeroNotixlipstick on a pig
16:50fortruceWhy doesn't ring-json wrap-json-response set the content-type to application/json?
16:57godd2How do I force an infinite loop to break in lein repl?
16:57godd2Ctrl-C doesn't work
17:10AeroNotixgodd2: C-b usually works for me
17:13godd2I tried C-b and C-c C-c and C-c C-b, none of them
18:18lodingfredericks, justin_smith: Thanks. How do I adapt the code to make unchecked-multiply use * and not multiply?
18:22gfrederickslodin: what does your code look like?
18:22gfredericks,(unchecked-multiply (identity 25214902975) 0x5DEECE66D)
18:22clojurebot#<ArithmeticException java.lang.ArithmeticException: integer overflow>
18:22gfredericks,(unchecked-multiply ^long (identity 25214902975) 0x5DEECE66D)
18:22clojurebot8602057284977698131
18:23gfredericks^ that I guess
18:27godd2,(*' 25214902975 0x5DEECE66D) ;; do you want the result of the overflow or the mathematically correct answer?
18:27clojurebot635791355791102453075N
18:27lodinExcellent.
18:27lodingodd2: Overflow.
18:28lodin(inc gfredericks)
18:28lazybot⇒ 120
18:29gfredericks,(* 2 2 2 3 5)
18:29clojurebot120
18:29justin_smith,(bit-and Long/MAX_VALUE (*' 25214902975 0x5DEECE66D))
18:29clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: bit operation not supported for: class clojure.lang.BigInt>
18:29godd2it's a pretty nice number
18:29justin_smith:P
18:31lodin,(apply * (range 1 (inc 5)))
18:31clojurebot120
18:32gfredericksnice
18:32hyPiRion,(bit-and Long/MAX_VALUE ('* 25214902975 0x5DEECE66D)) ;; totally fixed that for you, justin_smith
18:32clojurebot25214903917
18:32gfredericks,(->> 5 inc (range 1) (apply *))
18:32clojurebot120
18:33lodingfredericks: Which is better, a factorial or a square?
18:33gfredericksfactorials are rarer
18:33godd2factorials are recursiver
18:33lodingfredericks: Make sure you're not inc:ed then. :-)
18:33gfredericksoh hey a square is next isn't it
18:33lodin,(* 11 11)
18:33clojurebot121
18:36godd2,(apply * (take 2 (repeat 11)))
18:36clojurebot121
18:40gfredericks,(* 2 61)
18:40clojurebot122
18:44brkpnthi, why this is not tail recursive? http://pastebin.com/VvhQemcc. If i use huge numbers a Stackoverflow happends.
18:45justin_smithbrkpnt: there is no automatic tail recursion in Clojure, period
18:45justin_smithif you didn't call recur or trampoline, it's guranteed to not be a tail recursion
18:46splunkis there a protocol for "returns a map" like there's a protocol for "returns a seq"?
18:46justin_smitherr, s/tail recursion/optimized tail recursion/ in both those places, obviously
18:46spearofsolomonhi everyone
18:47gfredericksit's going to be so awkward when the jvm gets TCO
18:47justin_smithgfredericks: heh
18:47spearofsolomonI have a question about maps. If I store a number in a map, when I pull it out and try to number things with it, clojure tells me that it can't cast a mapentry to a number
18:47gfredericksI guess java devs will be in the same position
18:47justin_smithspearofsolomon: use get instead of find
18:48spearofsolomonOk
18:48justin_smith,(find {:a 0} :a)
18:48clojurebot[:a 0]
18:48justin_smith,(get {:a 0} :a)
18:48clojurebot0
18:48spearofsolomonI couldn't quite understand from the documentation what the difference between get and find is
18:48justin_smiththere is also val
18:48spearofsolomonexcept that get has an optional not-found
18:48justin_smith,(val (find {:a 0} :a))
18:48clojurebot0
18:49justin_smithspearofsolomon: get also works on sets and vectors (by identity or index, respectively)
18:52nicferrierI've found a slightly strange problem... if I try and read a particular structure with a key like :a1:b1 in it clojure barfs.
18:52justin_smith:a1:b1 is not valid
18:52justin_smith,:a1:b1
18:52clojurebot:a1:b1
18:53justin_smitherr...
18:53justin_smithwait...
18:53gfredericksI think hiccup has been using that for a while?
18:53justin_smitheverything I know is wrong
18:53gfredericksor something
18:53justin_smithdon't mind me
18:53gfredericksbut I do think the official docs don't say you can do that
18:53nicferrieryesh. it is valid. but clojure barfs... but only in particular circumstances.
18:53gfrederickswhat are they?
18:53nicferrierhiccup is a bit of a pita
18:55nicferrierwell I can't copy the exact sequence .... but some thing like [:a1 {:a2 "blah} [:a3 {:ac3:b2 "blah"} "str"] [:ac4 "blah"]]
18:55nicferrierand I note the elisp reader is struggling with that as well
18:55gfredericksand just typing that in your repl gives an exception?
18:55nicferrieryep.
18:55gfredericks,[:a1 {:a2 "blah} [:a3 {:ac3:b2 "blah"} "str"] [:ac4 "blah"]]
18:55clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading string>
18:55nicferrieroh whoops.missed a quote
18:56nicferrieroff the first blah
18:56nicferrierit's not that
18:56gfredericks,[:a1 {:a2 "blah"} [:a3 {:ac3:b2 "blah"} "str"] [:ac4 "blah"]]
18:56clojurebot[:a1 {:a2 "blah"} [:a3 {:ac3:b2 "blah"} "str"] [:ac4 "blah"]]
18:56nicferrierthat was just me retyping it
18:56gfrederickswell if you can't show us one that fails then I'm not sure how else we'll be able to help
18:56nicferrieryes. as I say, it's something like that.
18:56nicferrieryes. :-(
18:56gfrederickshow do you know it has to do with these keywords?
18:56clojurebotIt's greek to me.
18:57nicferriergfredericks: because I've got quite a simple form and I've normalized the kw and it's fine
18:57justin_smithnicferrier: what isthe specific exception you get?
18:57nicferrierand non-normalized it dies
18:57nicferrierI get an EOF
18:58gfredericksnicferrier: why can't you share the actual form?
18:58nicferriergfredericks: it's locked inside a bank
18:59nicferrierI should really make a tool to make it easier to open a scratch session with clojure from inside emacs.
18:59nicferriermy workflow is too tied to lein atm
19:01nicferrierre-creating it is a struggle
19:01justin_smithjava -jar path/to/clojure.jar
19:01justin_smiththough adding other deps is a pain
19:01nicferrieryeah... but I want it in emacs. s'alright. I'll get it done.
19:02nicferrierall my clojure tools are locked inside the same stupid bank.
19:02kwladyka(#{\a} \a) <- what exatly is this doing? i don't understand this line
19:02justin_smithnicferrier: C-u m-x inferior-lisp<ret>java -jar path/to/clojure.jar
19:02nicferrierjustin_smith: I KNOW :-)
19:02justin_smithkwladyka: it looks up \a in a set
19:03kwladykajustin_smith but how to know that? where can i some hints to discover that myself?
19:04kwladykahttp://clojure.org/cheatsheet <- example i am there and i cant find hints to understand this line, what i miss?
19:04gfredericksthere are some things that are hard to look up
19:04gfrederickslike "what things are functions?"
19:05justin_smithkwladyka: gfredericks: there is a page in the official clojure docs about readable forms that includes sets, macros, anonymous function shorthand, etc.
19:05kwladykai have big problem to undestand when use what :)
19:05justin_smithI am looking for it at the moment
19:06amalloyi think it's clojure.orc/reader
19:06amalloy*org
19:06gfredericksthose damn orcs got icann to give them a tld?
19:07justin_smithyup http://clojure.org/reader <- kwladyka that's your link
19:07nicferrierwell. I can't recreate it. I guess it might be a windows thing.
19:07justin_smithgfredericks: it's for orchestras
19:07justin_smith(inc amalloy)
19:07lazybot⇒ 234
19:08justin_smithright when I was about to find it, too :)
19:08amalloyif only i could sell licenses to amalloydb
19:08justin_smithhaha
19:08kwladykajustin_smith thx\
19:08kwladykauh i think its too late... its time to go sleep :)
19:09kwladykagoodnight all!
19:09shafireHi, I am trying to call Clojure from JRuby
19:09shafirewhat is wrong with this code? https://gist.github.com/anonymous/42b8f165e22cf2910206
19:10shafirethe .class file does not contain the "bar" function :(
19:10justin_smithshafire: no, it wouldn't. it would contain a -bar function
19:10justin_smiththat would be a .bar method on the Foo0 class
19:10nicferrierif I have cr's in it, it won't be read
19:10gfredericksshafire: you might have more luck with clojure's dynamic interface class
19:11gfredericksI forget what it's called
19:11gfredericksclojure.lang.api.Clojure or something
19:11amalloyclojure.java.api.Clojure
19:11shafirejustin_smith: there is no .bar methid on the Foo0 class
19:11justin_smithshafire: that's weird, the -bar definition should hve created one I thought
19:12shafireI am using clojure 1.6.0
19:12amalloydo you need to declare the methods you want to create in the :gen-class with :methods? i do'nt gen-class much
19:13nicferrierright - something like '([:a1 \n {:ac:b1 "hello"} \n [:anything]])
19:13nicferrierdoes not work. can someone do me a favour and confirm?
19:13amalloy,'([:a1 \n {:ac:b1 "hello"} \n [:anything]])
19:13clojurebot([:a1 \n {:ac:b1 "hello"} \n [:anything]])
19:13nicferrierof course the \n there are real cr's in the source
19:13nicferrierno, not the same thing.
19:14justin_smith,(read-string "([:a1 \n {:ac:b1 "hello"} \n [:anything]])")
19:14clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: hello in this context, compiling:(NO_SOURCE_PATH:0:0)>
19:14gfredericks,(read-string "([:a1 \r {:ac:b1 \"hello\"} \r [:anything]])")
19:14clojurebot([:a1 {:ac:b1 "hello"} [:anything]])
19:14justin_smithoops
19:14gfredericks,(read-string "([:a1 \n {:ac:b1 \"hello\"} \n [:anything]])")
19:14clojurebot([:a1 {:ac:b1 "hello"} [:anything]])
19:14nicferrierooo. good call. I'll try that
19:14amalloyi mean like, of course it works
19:15amalloyhave you checked the string you are copy-pasting for mysterious invisible unicode characters or something?
19:15nicferrieramalloy: I've retyped it.
19:15shafireis this for me?
19:16nicferrieramalloy: I've put it into a different computer with a different operating system.
19:16gfredericksshafire: is there any reason you can't use clojure.java.api.Clojure instead?
19:16TEttinger,(defn boms? [s] (re-find #"\ufeff" s))
19:16clojurebot#'sandbox/boms?
19:16TEttinger,(boms? "whee")
19:16clojurebotnil
19:16TEttinger,(boms? "wh\ufeff\ouch")
19:16clojurebot#<RuntimeException java.lang.RuntimeException: Unsupported escape character: \o>
19:16shafiregfredericks: do you have an example, how to use clojure.java.api.Clojure?
19:16TEttinger,(boms? "wh\ufeffouch")
19:16clojurebot""
19:17justin_smithhaha, I like how it returns a string with a bom in it
19:17justin_smithcheeky bom monkey
19:17TEttingerheh
19:17gfredericksshafire: http://clojure.github.io/clojure/javadoc/clojure/java/api/package-summary.html
19:17TEttingerbut that string is non-nil and so would count for a condition check
19:17justin_smiththat's true
19:19TEttingerI actually somehow had a BOM in one of my C# game's config files. of course the library I used wasn't meant to parse characters outside of ASCII, and was acting very strange
19:20nicferriercan someone try pasting it in to a clojure repl?
19:20nicferrier'([:a1
19:20nicferrier {:ac:b1 "hello"}
19:20nicferrier [:anything]])
19:20nicferriernot the one here... that's doing way too much conversion.
19:21justin_smithnicferrier: yeah, I get an eof in the middle of the form if I do it line by line like that
19:21nicferrierif I paste it in to lein repl just in a term, I get end of form after the }
19:21nicferrieryep. exactly what I get.
19:21justin_smithsecond line gives me an eof instead of a prompt for more input
19:21nicferrieryep.
19:21gfrederickswaaaaaaht
19:21nicferrierso there's a bug in the repl.
19:22justin_smithnicferrier: maybe, or it could be the answer is :ac:b1 is not a supported keyword syntax
19:22justin_smithand in other cases it only works accidentally
19:22nicferrierwell I don't think so.
19:22nicferrierok.
19:22nicferrierI ought to change parser. hiccup is annoying.
19:22justin_smithbut good chance we are looking at one of the two
19:23nicferrierbut I couldn't find another parser that would deal with shitty html.
19:23nicferrierI've got confluence here that I'm trying to parse.
19:23nicferriersigh.
19:23justin_smithI've typically used envlice
19:23justin_smith*enlive
19:24nicferrierok. will try that tmrw then.
19:25justin_smiththat's definitely a weird reader behavior though (I replicated it in a 1.6.0 repl)
19:25nicferrieryeah. am using 1.6 too.
19:25nicferriertake the cr out and all is well :-(
19:27shafireit works now with gen-class, it was the missing :methods, thanks to amalloy
19:27shafirethanks to gfredericks too
19:27nicferrierenlive looks more of a templating engine than a parser.
19:27justin_smithin my experience it parses well
19:29nicferrierI'm sure. if you can find the docs.
19:29nicferrieroh woe. everything is not perfect.
19:35nicferriertagsoup no good either. meh. I am going to bed disappointed.
19:45justin_smithnicferrier: with enlive I use (-> text StringReader. enlive/html-resource)
19:45justin_smiththough there might be something simpler
19:45justin_smithwhere enlive/ is net.cgrand.enlive-html/
19:48nicferriercheers justin_smith. will try it.
19:49justin_smithand that's java.io.StringReader, natch
19:50nicferriergot a bad namespace with a bad namespace. not good. :-)
19:51justin_smithoh, yuck
19:51justin_smithsorry to hear
19:51nicferrieroh. no. clojure ns. not xml one :-)
19:51nicferriermust go to bed.
19:51nicferriernight.
20:26enn`Is it possible to see the watches that are set on an instance of a reference type?
20:26gfredericksprobably
20:44gfredericks,(clojure.repl/apropos "watch")
20:44clojurebot(clojure.core/add-watch clojure.core/remove-watch)
20:45gfredericks,(.getWatches (atom 0))
20:45clojurebot{}
20:45gfredericksenn`: ^
20:46gfredericksit's pretty basic; each reference has a persistent map from keys to functions
20:46gfrederickssee clojure/lang/ARef.java if you're interested
23:35jack0Hi, are there any mentors for gsoc here?