#clojure logs

2015-10-15

00:00TEttinger,(map #(for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))]) (range (count (apply max-key count (vals rhg-data)))))
00:00clojurebot(([:a 1] [:b 2] [:c 4]) ([:a 1] [:b 3] [:c 5]) ([:a 1] [:b 2] [:c 6]))
00:00TEttingerphew, rhg135
00:00TEttinger,(map #(into {} (for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))])) (range (count (apply max-key count (vals rhg-data)))))
00:00clojurebot({:a 1, :b 2, :c 4} {:a 1, :b 3, :c 5} {:a 1, :b 2, :c 6})
00:01TEttingerI'm guessing you wanted all permutations or something
00:01rhg135that's some gnarly code
00:01TEttingernow that I read the question
00:01rhg135maybe I need to rethink my approach
00:12JayhostHey! Are you coffee or tea people here?
00:21l1xhey guys
00:22l1xis there an easy way to have only positive values from a hash function like murmur3?
00:22l1xhttps://gist.github.com/l1x/7c9cae8070c3e84a0f0e
00:37TEttingerl1x: sure
00:37l1xconverting it to binary and shifting it?
00:37TEttinger,(unsigned-bit-shift-right (hash -1) 1)
00:37clojurebot825930356
00:37TEttinger,(hash -1)
00:37clojurebot1651860712
00:37TEttingerhm
00:37TEttingerthat's odd
00:38TEttingerhash used to hash numbers as themselves, I thought...
00:38TEttinger,(map hash (rang -10 10))
00:38clojurebot#error {\n :cause "Unable to resolve symbol: rang in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: rang in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: rang in this co...
00:38TEttinger,(map hash (range -10 10))
00:38clojurebot(-1675778087 -714281095 -1517383352 -1703207563 522362154 ...)
00:38TEttinger,(unsigned-bit-shift-right (hash -10) 1)
00:38clojurebot9223372036016886764
00:39TEttingerthat does discard the least significant bit, overwriting it with the one more significant
00:39TEttingerso you're twice as likely to have hash collisions, maybe
00:39l1xthat does not matter
00:39TEttingerif hash returns a 32-bit int, you're golden though
00:40l1xwhat is the hash defn?
00:41TEttingerto clojure.core!
00:41TEttingerhttps://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L4937
00:42l1xi see
00:42TEttingerit's calling something defined in the java source of the clojure lib
00:42l1x(murmur-int "a3a")
00:42l1x-161652959486184562448573335884646282847
00:43l1xIllegalArgumentException bit operation not supported for: class java.math.BigInteger clojure.lang.Numbers.bitOpsCast (Numbers.java:1097)
00:43TEttinger,(unsigned-bit-shift-right -161652959486184562448573335884646282847 1)
00:43clojurebot#error {\n :cause "bit operation not supported for: class clojure.lang.BigInt"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "bit operation not supported for: class clojure.lang.BigInt"\n :at [clojure.lang.Numbers bitOpsCast "Numbers.java" 1097]}]\n :trace\n [[clojure.lang.Numbers bitOpsCast "Numbers.java" 1097]\n [clojure.lang.Numbers unsignedShiftRight "Numbers.java" 408]\n...
00:43TEttingeroh
00:43TEttingerwell that's going to throw a wrench in things, but!
00:43l1x:D
00:45TEttinger,(,abs -161652959486184562448573335884646282847N)
00:45clojurebot#error {\n :cause "Unable to resolve symbol: abs in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: abs in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: abs in this conte...
00:45TEttinger,(.abs -161652959486184562448573335884646282847N)
00:45clojurebot#error {\n :cause "No matching field found: abs for class clojure.lang.BigInt"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: abs for class clojure.lang.BigInt"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceM...
00:46l1x (.shiftRight (murmur-int "a3a") 1)
00:46l1x-80826479743092281224286667942323141424
00:47l1xwhat is x >>> 1 in Java?
00:48TEttingershiftRight won't work here, and BigInteger doesn't have a >>> equivalent
00:48TEttingerso
00:48l1xdamn
00:48TEttingershiftRight (or >> in Java) moves all the bits except for the sign bit to the right by the second arg
00:48l1xright
00:49TEttinger>>> is a logical or unsigned shift, and it will shift the sign bit over, replacing it with 0
00:49TEttinger,(.abs (biginteger -161652959486184562448573335884646282847N))
00:49clojurebot161652959486184562448573335884646282847
00:50TEttingerso that's one way to ensure they're positive
00:51TEttinger,(defn big-positive [n] (.abs (biginteger n)))
00:51clojurebot#'sandbox/big-positive
00:51TEttinger,(big-positive -1)
00:51clojurebot1
00:51l1xwell yes
00:52l1xbut i need this to determine the location of something in a BitSet
00:52TEttinger,(.xor (biginteger -161652959486184562448573335884646282847N) (biginteger -161652959486184562448573335884646282847N))
00:52clojurebot0
00:52TEttingerhm
00:52l1xworst case i can check abs
00:53TEttinger,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftLeft (biginteger -161652959486184562448573335884646282847N) 16))
00:53clojurebot10594100828800902576314882703235656096516513
00:53TEttingernot sure if that actually works
00:53TEttinger,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftRight (biginteger -161652959486184562448573335884646282847N) 1))
00:53clojurebot92151082097685838618080676853663321457
00:53TEttingerthe second should actually sorta do the trick
00:54TEttingerI'm not sure what you mean about the bitset
00:54TEttingerI'm familiar, somewhat with BitSet as a class
00:54TEttingerI don't think storing 92151082097685838618080676853663321457 bits will be possible
00:57TEttingerl1x: can you describe what you're trying to do with this from a more "broad goals" perspective?
00:58l1xi am trying to set the bit for a certain location in the BitSet
00:58l1xi see
00:58l1xi can use the 32 bit version in that case
00:59TEttingeryeah, I don't think BitSet takes a BigInteger for a location, heh
00:59l1xgood point!
01:00l1xBigInteger() has an implementation where you can pass in the output of this -> Bytes/toArray
01:01l1xi am wondering what is the same for Integer
01:01TEttingererr
01:01TEttingerl1x do you want to turns a byte[4] into a single 32-bit int?
01:02l1xyes
01:02l1x(BigInteger. (Bytes/toArray b)) works
01:04l1xbut not sure what is the same for integers
01:05l1xhttps://gist.github.com/pingles/1235344
01:05l1xmaybe this
01:07TEttinger,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 0 255 255])) 0)
01:07clojurebot65535
01:08TEttingerwhat is Bytes/toArray ? is it a standard Java class, Bytes?
01:10TEttinger,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 255 255])) 0) ; I suspect it needs a full 4 bytes
01:10clojurebot#error {\n :cause nil\n :via\n [{:type java.lang.IndexOutOfBoundsException\n :message nil\n :at [java.nio.Buffer checkIndex "Buffer.java" 538]}]\n :trace\n [[java.nio.Buffer checkIndex "Buffer.java" 538]\n [java.nio.HeapByteBuffer getInt "HeapByteBuffer.java" 359]\n [sandbox$eval49 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval49 invoke "NO_SOURCE_FILE" -1]\n [clojure.lang.Compiler eval ...
01:52keep_learningHello everyone.
01:52keep_learningAny idea how to resolve this error http://lpaste.net/143057
02:08Kneivakeep_learning: https://github.com/dakrone/clojure-opennlp/issues/2
02:08keep_learningKneiva: Thank you very much.
02:10Kneivakeep_learning: np
03:19vrdhn#nikola
03:32SeyleriusOkay, so, I was following the readme (https://github.com/josephwilk/image-resizer) for image-resizer, and the section about lazy helpers uses "file" a lot, as does the section on making BufferedImage useful. I tried writing my cropped image out, realized I had to require file from clojure.java.io, and now it's complaining about "NullPointerException javax.imageio.ImageIO.write (ImageIO.java:1538)". What's the problem here?
03:44SeyleriusFixed it. It just didn't want bare filenames for paths ("test.jpg"), and preferred slightly more proper paths ("./test.jpg").
04:44SeyleriusOkay, I've got a png barcode, and I want to add an annotation to the png, below the barcode, with the barcode's content and the price of the item. How would y'all go about such a thing?
05:14skoude /join #saltstack
06:01noncomSeylerius: do you have to recognize what the barcode says or do you simply need to put some image next to it?
06:11WickedShellI've got to be an idiot, I'm attempting to set a byte array in a java class member via interop, and for some reason it keeps getting the passed byte array's toString. The line of clojure is (set! (.param_id paramSet) (.getBytes s)) the java field is specified as: public byte param_id[] = new byte[16];
06:11WickedShellThis has to be easy but apparently I can't figure it out
06:24WickedShellThe anwser apparently is a weird mangled expression of java interop code, oh well I guess it works. For posterity the best I found was this: (System/arraycopy (.getBytes s) 0 (.param_id paramSet) 0 (count s))
07:49ashwink005does anyone know how to get data out of a Class HttpInput object?
07:50ashwink005slurp is giving an empty string
07:51Kneivaashwink005: org.eclipse.jetty.server.HttpInput ?
07:51ashwink005Kneiva, yes
07:51puredangerWickedShell: I'd be careful about count there depending what s is
07:51ashwink005I'm getting that object in my request body. I needed to parse its contents
07:53Kneivaashwink005: Well, that is a InputStream so you'll need some kind of StreamReader.
07:54ashwink005Kneiva, yeah saw that. How do you reckon I read it? the java way?
07:55KneivaOh, wait... let me check something.
07:59Kneivaashwink005: Hmm, I have some vague memory about ring or compojure or something closing the stream before it is handed out to your code. But I couldn't find anything related in the project where I run into that.
08:04necronianCan anyone explain to me what happens when I extend a java type? I extended java.lang.Number. But I don't understand why I can't call (.method 1) and instead need to call (method 1)?
08:09noncomnecronian: i'm not sure, but you can always look at clojure source. my explanation would be that a multimethod or a protocol dispatch is created for that type
08:23necroniannoncom: Yea... I just took a quick look. The amount I understand is only enough that figuring anything out will be a major project. For the time being I've decided the answer is magic and put a big fat ;;TODO: in there.
08:23noncomnecronian: that's ok. you mean extend java type like with (proxy) ?
08:28necroniannoncom: No I never knew about proxy before now. I created a Unit record that implements a UnitConversion protocol. Then I decided it would be nice for numbers to be dimensionless units for math purposes so I have (extend java.lang.Number UnitConversion {etc})
08:28noncomah i see
08:31noncomnecronian: well, looking at it - it generates a java interface
08:31noncomnecronian: really, i cannot say much more too, without some thorough reading into the code
08:32noncombut some folks here could tell. probably they're just not here
08:33necroniannoncom: Yea, thank you. It isn't a huge deal, it just makes my code less pretty when I use it in another namespace.
08:33noncomnecronian: you mean you then need to qualify it like (namespace/method obj ...) ?
08:34noncomif this is the problem, maybe :refer could help
08:34noncominteresting topic all in all. i'd like to hear someone on this
08:35noncomnever used protocols, actually :)
08:36WickedShellpuredanger, it's a string, is that still unsafe?
08:37necroniannoncom: Exactly. I could use refer but I would prefer to prefix it. I just thought it was strange that I get java methods when I create my own type but not when I extend a java type.
08:40noncomnecronian: from what i see in the code, it looks like that these are simple clojure functions, not any kind of java method generation... :/ that's why... surely there is a reason for that, but idk :)
08:42ashwink005I have an inputstream object and it has already been read
08:42ashwink005can I set its read pointer back to the beginning?
08:44noncomashwink005: (.reset input-stream) ?
08:45noncomashwink005: but first you have to call (.mark input-stream)
08:45noncomto put the mark where to return to
08:46ashwink005noncom, why do I need to put a mark.
08:46noncomdoes not work on all streams though
08:46ashwink005the stream has been read completely. Slurp returns an empty string.
08:46noncomashwink005: idk. propbably because various implementations must somehow play together...
08:46noncomno, i don't think it is possible
08:46noncomwhat is the underlying object?
08:47ashwink005HttpInput
08:47noncomashwink005: http://stackoverflow.com/questions/9501237/read-stream-twice
08:47noncomashwink005: http://stackoverflow.com/questions/13196742/java-inputstream-mark-reset
08:48noncomashwink005: this can also be useful: http://stackoverflow.com/questions/6716777/inputstream-will-not-reset-to-beginning
08:49ashwink005noncom, turns out HttpInput doesn't support reset/mark.
08:50noncomashwink005: then try the first link, where they copy it into a bytearray
08:50ashwink005compojure api is reading my request's body. I don't have a control over that. I just have an already read HttpInput
08:51ashwink005is there a way I could reuse that? or should I hack compojure-api?
08:59Kneivaashwink005: Have you seen this? http://ujihisa.blogspot.fi/2011/12/read-raw-post-request-body-in-compojure.html
09:00puredangerWickedShell: yeah, the number of characters in a string != number of bytes
09:02ashwink005Kneiva, I'm using compojure-api. Its a framework built on top of compojure
09:02ashwink005it does request validation and web-api doc generation
09:04Kneivaok, I'm not familiar with that
09:04Deraenashwink005: Compojure-api just uses ring-middleware-format
09:06ashwink005Deraen, yeah I guess
09:08Deraenashwink005: Also, might be a bug because I think that r-m-f is trying to recreate new inputstream if it reads the body
09:09Deraenashwink005: https://github.com/ngrunwald/ring-middleware-format/blob/master/src/ring/middleware/format_params.clj#L104-L118 perhaps it should create new inputs stream on line 118
09:12ashwink005Deraen, hmm.. so what should I do. No way I could reuse the HTTPInput?
09:12Deraenashwink005: HTTPInput is an InputStream
09:12ashwink005Deraen, yes
09:17WickedShellpuredanger: I thought it is given that the string was build by reading a cstring and I know that the encoding is ascii (or at least started in ascii). I'm a bit taken aback at how frustrating I'm finding it to be using libraries that need cstrings in clojure/java
09:22WickedShellpuredanger, I guess you're right in that to be truly safe/future proof I need to use getBytes where I provide the expected encoding, then cache the result, calculate the size of the resultant byte array, then do the copy while being careful not to exceed destination length. (Apparently I dont mind doing this at all in C normally but I resent the need to do it in clojure/java for some reason). But you're right, my stuff is only worki
09:22WickedShellng there as I've controlled the inputs pretty carefully at the moment
09:24Deraenashwink005: R-m-f doesn't have support for using InputStream mark/reset and I don't that HttpInput does support mark/reset either (it doesn't implement the necessary methods)
09:26ashwink005Deraen, yeah I saw that. I tried wrapping it in a BufferedInputStream but it keeps saying invalid mark
09:27justin_smithfor non streaming / websocket purproses I have had good luck capturing the HTTPInput via slurp into a string, and recreating via a new InputStream created from the String. This is great for turning a request that exposes a bug into a unit test
09:27justin_smithmake that non-streaming and non-websocket purposes
09:27Deraenashwink005: If you don't need r-m-f middleware you can mostly disable it by setting compojure-api :format :formats to empty vector
09:28ashwink005Deraen, hmm.. will try that.
09:30ashwink005justin_smith, I actually don't have any control over the HttpInput object. It is read by the compojure-api and is then rendered useless.
09:31justin_smithashwink005: you can hijack it with another middleware before compojure-api sees it
09:31justin_smithI have done weirder things
09:31justin_smitheg, grab it clone it, replace it with the clone, do what you want with the original
09:31justin_smiththe clone being a new inputstream so the other apis work, of course
09:32justin_smithevery middleware problem can be solved with yet more middleware :P
09:53SeyleriusHrm. How would one best turn a png barcode into a png with the barcode above the barcode ID number and the product's price?
09:53xemdetiaI was stuck on this at like some weird hour this morning but was there ever a fix for nrepl opening an ipv6 socket instead of an ipv4 socket on java 8 without just going back to java 7
09:55justin_smithwhat's wrong with ipv6?
09:55xemdetianothing really, I just can't get other stuff to connect to it
09:55justin_smithahh, that suskcs
09:55xemdetiawell monroe was what Iw as trying to use
09:55justin_smithoh, so no ipv6 for emacs? that's surprising actually
09:56xemdetiaI did compile it myself because I wanted svg support
09:56xemdetiaso I could have just did something wrong
09:56xemdetiaoh well, I'll have to play with it more now that coffee has re-entered my life
09:57justin_smithxemdetia: my guess is if the right dev headers for compiling ipv6 support had been present, emacs would have built support for ipv6 - not sure of that though
09:58justin_smithxemdetia: in emacs, "make-network-process" requires an explicit arg to use ipv6 - it might be as simple as hacking the elisp for monroe to try the ipv6 option
09:59xemdetiainteresting
09:59xemdetiaI will have to play with that leter
10:01justin_smithxemdetia: aha! monroe uses a higher level function, open-network-stream maybe this is relevant? https://lists.gnu.org/archive/html/emacs-devel/2004-10/msg01378.html
10:03justin_smithalso, you really should only be connecting to nrepl from localhost, so can't you use /etc/hosts to make sure localhost is ipv4?
10:04xemdetiaIt is sadly
10:04xemdetiamy /etc/hosts does resolve appropriately with 127.0.0.1, but the 127.0.0.1 appears on the tcp6 stack and not on the tcp stack
10:04xemdetiawhich is funky in general
10:04justin_smiththat's super weird
10:05xemdetiathere was an envvar I didn't get to try I found before I went to bed last night where there was a java 8 property to bias the ipv4 stack
10:05xemdetiaIt just looks like I have to do a little wrenching over lunch to figure it out
10:11jonathanjis there a shorter spelling of (every? true? ...)?
10:12justin_smith(= (set c) #{true})
10:12jonathanjthat's not terribly obvious though
10:13jonathanji guess worst case: (def all? (partial every? true?))
10:13justin_smithjonathanj: wait...
10:13justin_smith,(every true? [true true true])
10:13clojurebot#error {\n :cause "Unable to resolve symbol: every in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: every in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: every in this...
10:13justin_smith,(every? true? [true true true])
10:13clojurebottrue
10:14justin_smithis that really the function you want?
10:14justin_smith,(every? true? [true true true :truthy])
10:14clojurebotfalse
10:14justin_smithjust asking because it's extremely limited, not that it's never useful
10:14luma,(every? identity [true true :truthy])
10:14clojurebottrue
10:14jonathanjthe code in question is something like (every? true? (map verify-x xs))
10:15justin_smithOK
10:15jonathanjwhere verify-x returns a boolean
10:15jonathanjso i think it is what i want
10:15justin_smithcool
10:15jonathanji guess (apply and (map verify-x xs)) would also work?
10:15lumathen why not do (every? verify-x xs)
10:15jonathanjoh wait, and is a macro
10:15justin_smithjonathanj: no, because true? is only true for true itself
10:16justin_smithnot for any other value
10:16jonathanjluma: good idea!
10:16justin_smithluma: that's the ticket, yeah
10:18jonathanjthanks
10:34justin_smith(every? #(= Double/NaN %) nil)
10:34justin_smith,(every? #(= Double/NaN %) nil)
10:35clojurebottrue
10:42jonathanjis there a library for constructing URIs in idiomatic Clojure?
10:42jonathanj(and deconstructing them)
10:43bordeltabernacle(+ 2 2)
10:43clojurebot4
10:46puredangerjonathanj:
10:46puredangerjonathanj: https://github.com/cemerick/url if you're specifically working with urls
10:47jonathanjhrm
10:47jonathanjif something returns (url ...) and you want to add to the path, what are your options?
10:48jonathanjthere is an example there (url base child) but that's not generally very useful if you have a url not a string
10:48jonathanj(url (str returned-url) child) seems a bit gratuitous
11:51timvisherwell i'm feeling quite senile right now. isn't here a boolean predicate?
11:54justin_smith,(boolean? true)
11:54clojurebot#error {\n :cause "Unable to resolve symbol: boolean? in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: boolean? in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: boolean...
11:54justin_smith,(contains? #{true false} true)
11:54clojurebottrue
11:54justin_smithtimvisher: I was equally senile
11:56timvisher,(map (partial instance? Boolean) [true false nil 0 1 "true" "false"])
11:56clojurebot(true true false false false ...)
11:56timvisherjustin_smith: any danger there?
11:56timvisherother than it not being portable
11:56justin_smithbut you can have things that are instances of boolean that are not true or false (it's degenerate, and not what you want, but possible)
11:56justin_smith,(Boolean. "false")
11:56clojurebotfalse
11:57justin_smith,(= false (Boolean. "false"))
11:57clojurebottrue
11:57timvisherjustin_smith: oh that's interesting. how hard would you have to work for that to happen?
11:57justin_smithtimvisher: I'm trying to remember the trick...
11:57timvisheryeah, but once you reify the Boolean it's for reelz a boolean right?
11:57justin_smith,(if (Boolean. "false") :huh? :OK)
11:57clojurebot:huh?
11:57timvisher,(Boolean. "ohai")
11:57clojurebotfalse
11:57timvisherheh. that's fun.
11:57justin_smithtimvisher: see the if above
11:58justin_smithso that returns true for "is it a boolean", but isn't anything useful, and isn't anything you want
11:58justin_smithtimvisher: that might be enough of a corner case for the instance? Boolean to be OK, but I like testing against true and false explicitly anyway
11:59timvisherjustin_smith: yeah. not a bad point :)
13:20pilneam i missing a good reason for get to take the map and then the key?
13:21danlarkinpilne: composition
13:21pilnei guess it would be worded "take this data and find this value" and not "find this value in this data"
13:29mavbozopilne, consistency: function that works on collection takes a collection as its first argument
13:29mavbozo,(assoc {:a 1 :b 2} :c 3)
13:30clojurebot{:a 1, :b 2, :c 3}
13:30mavbozo,(assoc [1 2 76] 2 3)
13:30clojurebot[1 2 3]
13:32pilnei am sure that i will grow to love the consistency (: it's just a learning process, is there a "clojure user's guide to java" that I could use to brush up without having to get balls-deep in java again?
13:38mavbozopilne, well, considering you already have previous experience with java, this tutorial should be a nice quickstart => http://clojure-doc.org/articles/language/interop.html
13:39pilneawesome (: thanks
13:40spaceplukany clojure-clr users around?
13:48timvisherjustin_smith: so it just you here now?
13:49timvisherslack has eaten t3h world? :'(
13:49jln_\q
13:49timvisherheh
13:49timvisherbetter than when i typed my password by mistake
13:49timvishermsg NickServ is so easy to mistype
13:54mavbozowhat? justin_smith has moved to slack?
13:54justin_smithI'm here, but also busy
13:57justin_smithmavbozo: also regarding "function that works on collection takes a collection as its first argument" - associative is the first argument, sequential the last
13:57justin_smithkind of, most of the time :P
13:59timvisherjustin_smith: :'( 🍻
14:36timvisheranyone familiar with a util function that prints a value in the context of a threading macro?
14:37timvisher,(-> 1 inc #(do (println %) %) inc)
14:37clojurebot#error {\n :cause "clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.ClassCastException\n ...
14:37luma,(-> 1 inc (doto println) inc)
14:37Wojciech_K,(->> 1 inc #(do (println %) %) inc)
14:37clojurebot2\n3
14:37timvisher,(-> 1 inc (#(do (println %) %)) inc)
14:37clojurebot#error {\n :cause "sandbox$eval76$fn__77 cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "sandbox$eval76$fn__77 cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers inc "Numbers.java" 112]}]\n :trace\n [[clojure.lang.Numbers inc "Numbers.java" 112]\n [sandbox$eval76 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval76 invoke "NO_SOURCE_FI...
14:37clojurebot2\n3
14:38timvisherluma: nice.
14:38justin_smith,(-> 1 inc (doto println) inc)
14:39clojurebot2\n3
14:39justin_smithtimvisher: ^
14:39timvisheryeah that's nice
14:39TEttingerthat was luma's , justin_smith
14:39timvisheri don't think i've used doto before
14:39justin_smithheh, oops
14:39timvisherhey, how do i implement fizzbuzz in clojure?
14:43timvisherakkad is surrounded by a dark forest but notices what may have been an animal trail years ago winding off into the foliage
14:46justin_smithakkad: as in s3-wagon-private?
14:46akkadjustin_smith: yes
14:47justin_smithyeah we use that
14:47akkadok so it's recommended. cool.
14:47akkadusing makefile to precache in s3
14:47justin_smiththe chef script uses s3cmd to grab the latest version
14:47justin_smithwhen building the server (or just updating a server to use a new jar)
14:47TEttinger(map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" true %) (range 101))
15:22zexperimentTEttinger: new favorite fizzbuzz
15:23timvisherheh. there are always those who cannot resist the siren call
15:34justin_smith,(map #(condp (comp zero? (comp (partial apply mod) reverse list)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101))
15:34clojurebot("FizzBuzz" 1 2 "Fizz" 4 ...)
15:36oddcullypoints, there are none
15:36justin_smithwell, very few at least
15:37justin_smithif we had flip I could have done (flip mod) instead of (comp (partial apply mod) reverse list)
15:37justin_smithand flip mod almost sounds like flip mode, you know, busta rymes
15:38oddcullyah there they are
15:38pilneone could write their own flip function though if something like that ends up being needed frequently?
15:38oddcullyyou hid your points well
15:38justin_smithpilne: indeed, but it would not have made my example more succinct
15:38pilnek
15:39justin_smithor would it have?
15:40pilnenot really
15:40justin_smith,(defn flip [f] #(apply f (reverse %&)))
15:40clojurebot#'sandbox/flip
15:40justin_smith,(map #(condp (comp zero? (flip mod)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101))
15:40clojurebot("FizzBuzz" 1 2 "Fizz" 4 ...)
15:47timvisherhow would you go about def a var instead of printing?
15:47timvisherassuming either -> or ->>?
15:47timvisher->> is easy (def var) would do it
15:47justin_smithyou can use ->> inside ->
15:47timvisherjustin_smith: ah. interesting.
15:48justin_smith,(-> * #(%) (->> (def a)))
15:48clojurebot#'sandbox/a
15:48justin_smith,a
15:48clojurebot#object[sandbox$_STAR___26 0x7570782d "sandbox$_STAR___26@7570782d"]
15:48timvisher,(-> 1 inc (->> (def foo)) inc)
15:48clojurebot#error {\n :cause "clojure.lang.Var cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.Var cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers inc "Numbers.java" 112]}]\n :trace\n [[clojure.lang.Numbers inc "Numbers.java" 112]\n [sandbox$eval72 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval72 invoke "NO_SOURCE_FILE" -1]\n ...
15:48justin_smithwell, you need doto still if you want to inc again after
15:49timvisherright. the idea here is mainly that you can, at any point in the thread, capture the value
15:49justin_smith,(-> * (#(%)) inc (doto (->> (def foo))) inc)
15:49clojurebot3
15:49justin_smith,foo
15:49clojurebot2
15:49justin_smithworked!
15:50justin_smithand it also looks super weird :P
15:51justin_smiththere should be a doto>
15:51justin_smithwhich would be to doto as ->> is to ->
15:53justin_smith,(-> * (#(%)) inc (as-> x (do (def foo x) x)) inc)
15:53clojurebot3
15:56amalloyjustin_smith: or without the doto, if you jsut deref the var in the -> chain
15:56amalloy,(-> * (#(%)) inc (->> (def foo) deref) inc)
15:56clojurebot3
15:58justin_smithahh, that's a nice trick