#clojure log - Oct 15 2015

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:00 TEttinger: ,(map #(for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))]) (range (count (apply max-key count (vals rhg-data)))))

0:00 clojurebot: (([:a 1] [:b 2] [:c 4]) ([:a 1] [:b 3] [:c 5]) ([:a 1] [:b 2] [:c 6]))

0:00 TEttinger: phew, rhg135

0:00 ,(map #(into {} (for [[k vs] rhg-data] [k (nth vs (mod % (count vs)))])) (range (count (apply max-key count (vals rhg-data)))))

0:00 clojurebot: ({:a 1, :b 2, :c 4} {:a 1, :b 3, :c 5} {:a 1, :b 2, :c 6})

0:01 TEttinger: I'm guessing you wanted all permutations or something

0:01 rhg135: that's some gnarly code

0:01 TEttinger: now that I read the question

0:01 rhg135: maybe I need to rethink my approach

0:12 Jayhost: Hey! Are you coffee or tea people here?

0:21 l1x: hey guys

0:22 is there an easy way to have only positive values from a hash function like murmur3?

0:22 https://gist.github.com/l1x/7c9cae8070c3e84a0f0e

0:37 TEttinger: l1x: sure

0:37 l1x: converting it to binary and shifting it?

0:37 TEttinger: ,(unsigned-bit-shift-right (hash -1) 1)

0:37 clojurebot: 825930356

0:37 TEttinger: ,(hash -1)

0:37 clojurebot: 1651860712

0:37 TEttinger: hm

0:37 that's odd

0:38 hash used to hash numbers as themselves, I thought...

0:38 ,(map hash (rang -10 10))

0:38 clojurebot: #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...

0:38 TEttinger: ,(map hash (range -10 10))

0:38 clojurebot: (-1675778087 -714281095 -1517383352 -1703207563 522362154 ...)

0:38 TEttinger: ,(unsigned-bit-shift-right (hash -10) 1)

0:38 clojurebot: 9223372036016886764

0:39 TEttinger: that does discard the least significant bit, overwriting it with the one more significant

0:39 so you're twice as likely to have hash collisions, maybe

0:39 l1x: that does not matter

0:39 TEttinger: if hash returns a 32-bit int, you're golden though

0:40 l1x: what is the hash defn?

0:41 TEttinger: to clojure.core!

0:41 https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L4937

0:42 l1x: i see

0:42 TEttinger: it's calling something defined in the java source of the clojure lib

0:42 l1x: (murmur-int "a3a")

0:42 -161652959486184562448573335884646282847

0:43 IllegalArgumentException bit operation not supported for: class java.math.BigInteger clojure.lang.Numbers.bitOpsCast (Numbers.java:1097)

0:43 TEttinger: ,(unsigned-bit-shift-right -161652959486184562448573335884646282847 1)

0:43 clojurebot: #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...

0:43 TEttinger: oh

0:43 well that's going to throw a wrench in things, but!

0:43 l1x: :D

0:45 TEttinger: ,(,abs -161652959486184562448573335884646282847N)

0:45 clojurebot: #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...

0:45 TEttinger: ,(.abs -161652959486184562448573335884646282847N)

0:45 clojurebot: #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...

0:46 l1x: (.shiftRight (murmur-int "a3a") 1)

0:46 -80826479743092281224286667942323141424

0:47 what is x >>> 1 in Java?

0:48 TEttinger: shiftRight won't work here, and BigInteger doesn't have a >>> equivalent

0:48 so

0:48 l1x: damn

0:48 TEttinger: shiftRight (or >> in Java) moves all the bits except for the sign bit to the right by the second arg

0:48 l1x: right

0:49 TEttinger: >>> is a logical or unsigned shift, and it will shift the sign bit over, replacing it with 0

0:49 ,(.abs (biginteger -161652959486184562448573335884646282847N))

0:49 clojurebot: 161652959486184562448573335884646282847

0:50 TEttinger: so that's one way to ensure they're positive

0:51 ,(defn big-positive [n] (.abs (biginteger n)))

0:51 clojurebot: #'sandbox/big-positive

0:51 TEttinger: ,(big-positive -1)

0:51 clojurebot: 1

0:51 l1x: well yes

0:52 but i need this to determine the location of something in a BitSet

0:52 TEttinger: ,(.xor (biginteger -161652959486184562448573335884646282847N) (biginteger -161652959486184562448573335884646282847N))

0:52 clojurebot: 0

0:52 TEttinger: hm

0:52 l1x: worst case i can check abs

0:53 TEttinger: ,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftLeft (biginteger -161652959486184562448573335884646282847N) 16))

0:53 clojurebot: 10594100828800902576314882703235656096516513

0:53 TEttinger: not sure if that actually works

0:53 ,(.xor (biginteger -161652959486184562448573335884646282847N) (.shiftRight (biginteger -161652959486184562448573335884646282847N) 1))

0:53 clojurebot: 92151082097685838618080676853663321457

0:53 TEttinger: the second should actually sorta do the trick

0:54 I'm not sure what you mean about the bitset

0:54 I'm familiar, somewhat with BitSet as a class

0:54 I don't think storing 92151082097685838618080676853663321457 bits will be possible

0:57 l1x: can you describe what you're trying to do with this from a more "broad goals" perspective?

0:58 l1x: i am trying to set the bit for a certain location in the BitSet

0:58 i see

0:58 i can use the 32 bit version in that case

0:59 TEttinger: yeah, I don't think BitSet takes a BigInteger for a location, heh

0:59 l1x: good point!

1:00 BigInteger() has an implementation where you can pass in the output of this -> Bytes/toArray

1:01 i am wondering what is the same for Integer

1:01 TEttinger: err

1:01 l1x do you want to turns a byte[4] into a single 32-bit int?

1:02 l1x: yes

1:02 (BigInteger. (Bytes/toArray b)) works

1:04 but not sure what is the same for integers

1:05 https://gist.github.com/pingles/1235344

1:05 maybe this

1:07 TEttinger: ,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 0 255 255])) 0)

1:07 clojurebot: 65535

1:08 TEttinger: what is Bytes/toArray ? is it a standard Java class, Bytes?

1:10 ,(.getInt (java.nio.ByteBuffer/wrap (byte-array [0 255 255])) 0) ; I suspect it needs a full 4 bytes

1:10 clojurebot: #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 ...

1:52 keep_learning: Hello everyone.

1:52 Any idea how to resolve this error http://lpaste.net/143057

2:08 Kneiva: keep_learning: https://github.com/dakrone/clojure-opennlp/issues/2

2:08 keep_learning: Kneiva: Thank you very much.

2:10 Kneiva: keep_learning: np

3:19 vrdhn: #nikola

3:32 Seylerius: Okay, 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?

3:44 Fixed it. It just didn't want bare filenames for paths ("test.jpg"), and preferred slightly more proper paths ("./test.jpg").

4:44 Okay, 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?

5:14 skoude: /join #saltstack

6:01 noncom: Seylerius: do you have to recognize what the barcode says or do you simply need to put some image next to it?

6:11 WickedShell: I'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];

6:11 This has to be easy but apparently I can't figure it out

6:24 The 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))

7:49 ashwink005: does anyone know how to get data out of a Class HttpInput object?

7:50 slurp is giving an empty string

7:51 Kneiva: ashwink005: org.eclipse.jetty.server.HttpInput ?

7:51 ashwink005: Kneiva, yes

7:51 puredanger: WickedShell: I'd be careful about count there depending what s is

7:51 ashwink005: I'm getting that object in my request body. I needed to parse its contents

7:53 Kneiva: ashwink005: Well, that is a InputStream so you'll need some kind of StreamReader.

7:54 ashwink005: Kneiva, yeah saw that. How do you reckon I read it? the java way?

7:55 Kneiva: Oh, wait... let me check something.

7:59 ashwink005: 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.

8:04 necronian: Can 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)?

8:09 noncom: necronian: 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

8:23 necronian: noncom: 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.

8:23 noncom: necronian: that's ok. you mean extend java type like with (proxy) ?

8:28 necronian: noncom: 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})

8:28 noncom: ah i see

8:31 necronian: well, looking at it - it generates a java interface

8:31 necronian: really, i cannot say much more too, without some thorough reading into the code

8:32 but some folks here could tell. probably they're just not here

8:33 necronian: noncom: Yea, thank you. It isn't a huge deal, it just makes my code less pretty when I use it in another namespace.

8:33 noncom: necronian: you mean you then need to qualify it like (namespace/method obj ...) ?

8:34 if this is the problem, maybe :refer could help

8:34 interesting topic all in all. i'd like to hear someone on this

8:35 never used protocols, actually :)

8:36 WickedShell: puredanger, it's a string, is that still unsafe?

8:37 necronian: noncom: 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.

8:40 noncom: necronian: 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 :)

8:42 ashwink005: I have an inputstream object and it has already been read

8:42 can I set its read pointer back to the beginning?

8:44 noncom: ashwink005: (.reset input-stream) ?

8:45 ashwink005: but first you have to call (.mark input-stream)

8:45 to put the mark where to return to

8:46 ashwink005: noncom, why do I need to put a mark.

8:46 noncom: does not work on all streams though

8:46 ashwink005: the stream has been read completely. Slurp returns an empty string.

8:46 noncom: ashwink005: idk. propbably because various implementations must somehow play together...

8:46 no, i don't think it is possible

8:46 what is the underlying object?

8:47 ashwink005: HttpInput

8:47 noncom: ashwink005: http://stackoverflow.com/questions/9501237/read-stream-twice

8:47 ashwink005: http://stackoverflow.com/questions/13196742/java-inputstream-mark-reset

8:48 ashwink005: this can also be useful: http://stackoverflow.com/questions/6716777/inputstream-will-not-reset-to-beginning

8:49 ashwink005: noncom, turns out HttpInput doesn't support reset/mark.

8:50 noncom: ashwink005: then try the first link, where they copy it into a bytearray

8:50 ashwink005: compojure api is reading my request's body. I don't have a control over that. I just have an already read HttpInput

8:51 is there a way I could reuse that? or should I hack compojure-api?

8:59 Kneiva: ashwink005: Have you seen this? http://ujihisa.blogspot.fi/2011/12/read-raw-post-request-body-in-compojure.html

9:00 puredanger: WickedShell: yeah, the number of characters in a string != number of bytes

9:02 ashwink005: Kneiva, I'm using compojure-api. Its a framework built on top of compojure

9:02 it does request validation and web-api doc generation

9:04 Kneiva: ok, I'm not familiar with that

9:04 Deraen: ashwink005: Compojure-api just uses ring-middleware-format

9:06 ashwink005: Deraen, yeah I guess

9:08 Deraen: ashwink005: Also, might be a bug because I think that r-m-f is trying to recreate new inputstream if it reads the body

9:09 ashwink005: 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

9:12 ashwink005: Deraen, hmm.. so what should I do. No way I could reuse the HTTPInput?

9:12 Deraen: ashwink005: HTTPInput is an InputStream

9:12 ashwink005: Deraen, yes

9:17 WickedShell: puredanger: 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

9:22 puredanger, 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

9:22 ng there as I've controlled the inputs pretty carefully at the moment

9:24 Deraen: ashwink005: 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)

9:26 ashwink005: Deraen, yeah I saw that. I tried wrapping it in a BufferedInputStream but it keeps saying invalid mark

9:27 justin_smith: for 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

9:27 make that non-streaming and non-websocket purposes

9:27 Deraen: ashwink005: If you don't need r-m-f middleware you can mostly disable it by setting compojure-api :format :formats to empty vector

9:28 ashwink005: Deraen, hmm.. will try that.

9:30 justin_smith, I actually don't have any control over the HttpInput object. It is read by the compojure-api and is then rendered useless.

9:31 justin_smith: ashwink005: you can hijack it with another middleware before compojure-api sees it

9:31 I have done weirder things

9:31 eg, grab it clone it, replace it with the clone, do what you want with the original

9:31 the clone being a new inputstream so the other apis work, of course

9:32 every middleware problem can be solved with yet more middleware :P

9:53 Seylerius: Hrm. How would one best turn a png barcode into a png with the barcode above the barcode ID number and the product's price?

9:53 xemdetia: I 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

9:55 justin_smith: what's wrong with ipv6?

9:55 xemdetia: nothing really, I just can't get other stuff to connect to it

9:55 justin_smith: ahh, that suskcs

9:55 xemdetia: well monroe was what Iw as trying to use

9:55 justin_smith: oh, so no ipv6 for emacs? that's surprising actually

9:56 xemdetia: I did compile it myself because I wanted svg support

9:56 so I could have just did something wrong

9:56 oh well, I'll have to play with it more now that coffee has re-entered my life

9:57 justin_smith: xemdetia: 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

9:58 xemdetia: 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

9:59 xemdetia: interesting

9:59 I will have to play with that leter

10:01 justin_smith: xemdetia: 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:03 also, you really should only be connecting to nrepl from localhost, so can't you use /etc/hosts to make sure localhost is ipv4?

10:04 xemdetia: It is sadly

10:04 my /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:04 which is funky in general

10:04 justin_smith: that's super weird

10:05 xemdetia: there 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:05 It just looks like I have to do a little wrenching over lunch to figure it out

10:11 jonathanj: is there a shorter spelling of (every? true? ...)?

10:12 justin_smith: (= (set c) #{true})

10:12 jonathanj: that's not terribly obvious though

10:13 i guess worst case: (def all? (partial every? true?))

10:13 justin_smith: jonathanj: wait...

10:13 ,(every true? [true true true])

10:13 clojurebot: #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:13 justin_smith: ,(every? true? [true true true])

10:13 clojurebot: true

10:14 justin_smith: is that really the function you want?

10:14 ,(every? true? [true true true :truthy])

10:14 clojurebot: false

10:14 justin_smith: just asking because it's extremely limited, not that it's never useful

10:14 luma: ,(every? identity [true true :truthy])

10:14 clojurebot: true

10:14 jonathanj: the code in question is something like (every? true? (map verify-x xs))

10:15 justin_smith: OK

10:15 jonathanj: where verify-x returns a boolean

10:15 so i think it is what i want

10:15 justin_smith: cool

10:15 jonathanj: i guess (apply and (map verify-x xs)) would also work?

10:15 luma: then why not do (every? verify-x xs)

10:15 jonathanj: oh wait, and is a macro

10:15 justin_smith: jonathanj: no, because true? is only true for true itself

10:16 not for any other value

10:16 jonathanj: luma: good idea!

10:16 justin_smith: luma: that's the ticket, yeah

10:18 jonathanj: thanks

10:34 justin_smith: (every? #(= Double/NaN %) nil)

10:34 ,(every? #(= Double/NaN %) nil)

10:35 clojurebot: true

10:42 jonathanj: is there a library for constructing URIs in idiomatic Clojure?

10:42 (and deconstructing them)

10:43 bordeltabernacle: (+ 2 2)

10:43 clojurebot: 4

10:46 puredanger: jonathanj:

10:46 jonathanj: https://github.com/cemerick/url if you're specifically working with urls

10:47 jonathanj: hrm

10:47 if something returns (url ...) and you want to add to the path, what are your options?

10:48 there is an example there (url base child) but that's not generally very useful if you have a url not a string

10:48 (url (str returned-url) child) seems a bit gratuitous

11:51 timvisher: well i'm feeling quite senile right now. isn't here a boolean predicate?

11:54 justin_smith: ,(boolean? true)

11:54 clojurebot: #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:54 justin_smith: ,(contains? #{true false} true)

11:54 clojurebot: true

11:54 justin_smith: timvisher: I was equally senile

11:56 timvisher: ,(map (partial instance? Boolean) [true false nil 0 1 "true" "false"])

11:56 clojurebot: (true true false false false ...)

11:56 timvisher: justin_smith: any danger there?

11:56 other than it not being portable

11:56 justin_smith: but 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:56 ,(Boolean. "false")

11:56 clojurebot: false

11:57 justin_smith: ,(= false (Boolean. "false"))

11:57 clojurebot: true

11:57 timvisher: justin_smith: oh that's interesting. how hard would you have to work for that to happen?

11:57 justin_smith: timvisher: I'm trying to remember the trick...

11:57 timvisher: yeah, but once you reify the Boolean it's for reelz a boolean right?

11:57 justin_smith: ,(if (Boolean. "false") :huh? :OK)

11:57 clojurebot: :huh?

11:57 timvisher: ,(Boolean. "ohai")

11:57 clojurebot: false

11:57 timvisher: heh. that's fun.

11:57 justin_smith: timvisher: see the if above

11:58 so that returns true for "is it a boolean", but isn't anything useful, and isn't anything you want

11:58 timvisher: 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:59 timvisher: justin_smith: yeah. not a bad point :)

13:20 pilne: am i missing a good reason for get to take the map and then the key?

13:21 danlarkin: pilne: composition

13:21 pilne: i guess it would be worded "take this data and find this value" and not "find this value in this data"

13:29 mavbozo: pilne, consistency: function that works on collection takes a collection as its first argument

13:29 ,(assoc {:a 1 :b 2} :c 3)

13:30 clojurebot: {:a 1, :b 2, :c 3}

13:30 mavbozo: ,(assoc [1 2 76] 2 3)

13:30 clojurebot: [1 2 3]

13:32 pilne: i 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:38 mavbozo: pilne, 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:39 pilne: awesome (: thanks

13:40 spacepluk: any clojure-clr users around?

13:48 timvisher: justin_smith: so it just you here now?

13:49 slack has eaten t3h world? :'(

13:49 jln_: \q

13:49 timvisher: heh

13:49 better than when i typed my password by mistake

13:49 msg NickServ is so easy to mistype

13:54 mavbozo: what? justin_smith has moved to slack?

13:54 justin_smith: I'm here, but also busy

13:57 mavbozo: also regarding "function that works on collection takes a collection as its first argument" - associative is the first argument, sequential the last

13:57 kind of, most of the time :P

13:59 timvisher: justin_smith: :'( 🍻

14:36 anyone familiar with a util function that prints a value in the context of a threading macro?

14:37 ,(-> 1 inc #(do (println %) %) inc)

14:37 clojurebot: #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:37 luma: ,(-> 1 inc (doto println) inc)

14:37 Wojciech_K: ,(->> 1 inc #(do (println %) %) inc)

14:37 clojurebot: 2\n3

14:37 timvisher: ,(-> 1 inc (#(do (println %) %)) inc)

14:37 clojurebot: #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:37 2\n3

14:38 timvisher: luma: nice.

14:38 justin_smith: ,(-> 1 inc (doto println) inc)

14:39 clojurebot: 2\n3

14:39 justin_smith: timvisher: ^

14:39 timvisher: yeah that's nice

14:39 TEttinger: that was luma's , justin_smith

14:39 timvisher: i don't think i've used doto before

14:39 justin_smith: heh, oops

14:39 timvisher: hey, how do i implement fizzbuzz in clojure?

14:39 * timvisher quits

14:42 * akkad looks for anyone who deploys via s3/lein

14:43 timvisher: akkad is surrounded by a dark forest but notices what may have been an animal trail years ago winding off into the foliage

14:46 justin_smith: akkad: as in s3-wagon-private?

14:46 akkad: justin_smith: yes

14:47 justin_smith: yeah we use that

14:47 akkad: ok so it's recommended. cool.

14:47 using makefile to precache in s3

14:47 justin_smith: the chef script uses s3cmd to grab the latest version

14:47 when building the server (or just updating a server to use a new jar)

14:47 TEttinger: (map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" true %) (range 101))

15:22 zexperiment: TEttinger: new favorite fizzbuzz

15:23 timvisher: heh. there are always those who cannot resist the siren call

15:34 justin_smith: ,(map #(condp (comp zero? (comp (partial apply mod) reverse list)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101))

15:34 clojurebot: ("FizzBuzz" 1 2 "Fizz" 4 ...)

15:36 oddcully: points, there are none

15:36 justin_smith: well, very few at least

15:37 if we had flip I could have done (flip mod) instead of (comp (partial apply mod) reverse list)

15:37 and flip mod almost sounds like flip mode, you know, busta rymes

15:38 oddcully: ah there they are

15:38 pilne: one could write their own flip function though if something like that ends up being needed frequently?

15:38 oddcully: you hid your points well

15:38 justin_smith: pilne: indeed, but it would not have made my example more succinct

15:38 pilne: k

15:39 justin_smith: or would it have?

15:40 pilne: not really

15:40 justin_smith: ,(defn flip [f] #(apply f (reverse %&)))

15:40 clojurebot: #'sandbox/flip

15:40 justin_smith: ,(map #(condp (comp zero? (flip mod)) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 101))

15:40 clojurebot: ("FizzBuzz" 1 2 "Fizz" 4 ...)

15:47 timvisher: how would you go about def a var instead of printing?

15:47 assuming either -> or ->>?

15:47 ->> is easy (def var) would do it

15:47 justin_smith: you can use ->> inside ->

15:47 timvisher: justin_smith: ah. interesting.

15:48 justin_smith: ,(-> * #(%) (->> (def a)))

15:48 clojurebot: #'sandbox/a

15:48 justin_smith: ,a

15:48 clojurebot: #object[sandbox$_STAR___26 0x7570782d "sandbox$_STAR___26@7570782d"]

15:48 timvisher: ,(-> 1 inc (->> (def foo)) inc)

15:48 clojurebot: #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:48 justin_smith: well, you need doto still if you want to inc again after

15:49 timvisher: right. the idea here is mainly that you can, at any point in the thread, capture the value

15:49 justin_smith: ,(-> * (#(%)) inc (doto (->> (def foo))) inc)

15:49 clojurebot: 3

15:49 justin_smith: ,foo

15:49 clojurebot: 2

15:49 justin_smith: worked!

15:50 and it also looks super weird :P

15:51 there should be a doto>

15:51 which would be to doto as ->> is to ->

15:53 ,(-> * (#(%)) inc (as-> x (do (def foo x) x)) inc)

15:53 clojurebot: 3

15:56 amalloy: justin_smith: or without the doto, if you jsut deref the var in the -> chain

15:56 ,(-> * (#(%)) inc (->> (def foo) deref) inc)

15:56 clojurebot: 3

15:58 justin_smith: ahh, that's a nice trick

Logging service provided by n01se.net