#clojure log - Nov 09 2015

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

0:17 fluffywaffles: any friendly clojure...ists? willing to help me answer a question?

0:17 I have a vector of 1s and 0s and I want to combine the 0s and sum the 1s

0:17 I feel like there should be an easy way to do it, but I'm hitting a wall

0:18 eg, [ 0 1 1 1 0 0 0 1 0 1 1 ] => [ 0 3 0 1 0 2 ]

0:26 TEttinger: ,(reduce #(if (= (zero? %2) (zero? (last %1))) (update %1 (dec (count %1)) (partial + %2)) (conj %1 %2)) [] [ 0 1 1 1 0 0 0 1 0 1 1 ])

0:26 clojurebot: #error {\n :cause nil\n :via\n [{:type java.lang.NullPointerException\n :message nil\n :at [clojure.lang.Numbers ops "Numbers.java" 1013]}]\n :trace\n [[clojure.lang.Numbers ops "Numbers.java" 1013]\n [clojure.lang.Numbers isZero "Numbers.java" 92]\n [sandbox$eval27$fn__28 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.PersistentVector reduce "PersistentVector.java" 337]\n [clojure.core$reduce...

0:28 TEttinger: ,(reduce #(if (and (seq %1) (= (zero? %2) (zero? (last %1)))) (update %1 (dec (count %1)) (partial + %2)) (conj %1 %2)) [] [ 0 1 1 1 0 0 0 1 0 1 1 ])

0:28 clojurebot: [0 3 0 1 0 ...]

0:28 TEttinger: yay

0:29 but fluffywaffles left

0:29 hiredman: ,(->> [ 0 1 1 1 0 0 0 1 0 1 1 ] (partition-by zero?) (map (partial apply +)))

0:29 clojurebot: (0 3 0 1 0 ...)

1:05 PMunch: I'm getting some weird behaviour trying to use signal handlers. Error message: Exception in thread "SIGINT handler" clojure.lang.ArityException: Wrong number of args (1) passed to:

1:06 I have the same kind of signal handling elsewhere in the program and it works fine. But this one instance just refuses to work..

1:11 TEttinger: PMunch: it doesn't say what fn is getting the wrong args?

1:11 weird

1:11 PMunch: TEttinger, it does I just removed it since it's program specific: core/create-node/reify--72/fn--73

1:11 TEttinger: ah ok

1:12 so this is an interop thing?

1:13 PMunch: Yea, I'm trying to catch SIGINT and SIGTERM to ensure the program shuts down cleanly

1:20 TEttinger: I'm guessing it might be related to reify maybe needing a this parameter or something like that, I can't remember how reify works

1:20 or it implicitly being given one, I dunno

1:21 PMunch: TEttinger, that would be weird since I have the exact same code somewhere else in the program but with different handlers..

1:21 So I know that the signal handler part should work

1:21 Hmm, in fact it does it's first println..

1:22 So the handler is actually being executed.

1:23 Hmm, looking at the function a bit closer it is actually complaining on a swap! call..

1:23 TEttinger: maybe you don't have an arg when it expects 2, or you're using swap! with a fn that expects no args?

1:24 reset! will just make an atom equal to a value

1:24 tmtwd: what does the single quote mean when requiring in clojure?

1:24 TEttinger: tmtwd: single quote means "don't run this" basically

1:25 tmtwd: i mean like this though (require '[honeysql.core :as sql]

1:25 PMunch: TEttinger, I figured it out. I had made an anonymous function #(...) for the swap and I had forgot to add the % argument.

1:25 TEttinger: it means you can have symbols like clojure.string without the program trying to figure out whatthey evaluate to

1:25 ahhh

1:25 ,[honeysql.core]

1:26 clojurebot: #error {\n :cause "honeysql.core"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: honeysql.core, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.ClassNotFoundException\n :message "honeysql.core"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\n [...

1:26 TEttinger: ,'[honeysql.core]

1:26 clojurebot: [honeysql.core]

1:26 TEttinger: tmtwd, that shows the difference, sorta. the quote makes it so it doesn't try to figure out what the things inside the brackets after it mean

1:27 in the first example, it tries to resolve what honeysql.core is

1:27 tmtwd: but then I get this error ava.lang.Exception: Found lib name 'honeysql.core' containing period with prefix 'quote'.

1:27 TEttinger: you don't need the quote when using :require in the ns macro, which is usually the first thing in a file

1:28 tmtwd: but then I get this error Could not locate honeysql/core__init.class or honeysql/core.clj

1:28 yes hsql is installed

1:28 in project.clj

1:28 TEttinger: ,(require '[clojure.string :as st])

1:28 clojurebot: nil

1:29 TEttinger: ,(st/join [1 2 3])

1:29 clojurebot: "123"

1:29 tmtwd: but I have the colon in front of require

1:29 ,(require [clojure.string :as s])

1:29 TEttinger: ah, is this in the ns section thing?

1:29 clojurebot: #error {\n :cause "clojure.string"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: clojure.string, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.ClassNotFoundException\n :message "clojure.string"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\...

1:29 tmtwd: yes

1:30 TEttinger: then you don't use the quote

1:30 tmtwd: ,(:require [clojure.string :as s])

1:30 clojurebot: #error {\n :cause "clojure.string"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: clojure.string, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.ClassNotFoundException\n :message "clojure.string"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\...

1:30 TEttinger: :require only makes sense in (ns)

1:30 tmtwd: http://pastebin.com/txMHwZHw

1:30 TEttinger: it's part of an instruction to the macro called "ns"

1:31 tmtwd: I'm trying to do this

1:31 but I get a Could not locate honeysql/core__init.class or honeysql/core.clj error

1:32 huh let me try a lein clean

1:33 TEttinger: good idea

1:36 tmtwd: yeah, isn't working, and its in the m2 repo directory too from which I draw all my libraries

1:48 oddcully: tmtwd: you have that dep in :dependencies [[honeysql "<ver>"]]?

1:48 it shows in lein deps :tree ?

1:48 you are trying to use it in a .clj file?

2:40 jeaye: What's a cleaner way of saying (rest (rest (rest foo)))?

2:40 Ah, drop!

2:41 mavbozo: nthrest, nthnext

2:42 jeaye: Good to know; drop will work here, too.

3:08 dstockton: to anyone using spacemacs, why is the line highlighting on the default theme so awful (yellow, can't read the text)?

4:13 kungi: why does (binding [foo "bar"] (map f coll)) not bind foo in f?

4:15 Bronsa`: kungi: dynamic binding and lazyness don't mix too good together

4:17 kungi: Bronsa: what about (binding [foo ...] (map (partial f foo) coll))

4:18 Bronsa: yes that would work

4:19 assuming your f goes from (fn [.. el] ..) to (fn [foo .. el] ..)

4:20 kungi: Bronsa: it does :-)

4:22 amalloy: well but there's no reason to use binding there. just use let

4:23 kungi: amalloy: There actually is a reason. foo is a var bound to the whole http request in my webapp. When I am testing this code I need to use binding.

4:23 baz_: morning, is it possible to access the project map while defining an alias?

4:24 in this particular case I would like to access the project version

4:24 kungi: baz_: You can slurp in the project.clj and extract the version.

4:24 amalloy: no, in the last example you pasted a binding is exactly the same as a let

4:24 kungi: baz_: At least that is what I am doing

4:25 amalloy: or indeed using neither at all and just (partial f ...)

4:25 baz_: kungi: thanks, will try that

4:39 kungi: :project/version also works in aliases

4:39 kungi: found the example project.clj, obviously :P

4:39 *found in

5:09 luma: because map returns a lazy sequence, so when the sequence is realized, it's not inside the binding anymore

5:09 oops, i was scrolled up

5:09 sorry

5:41 visof: hi guys

5:41 what is the performace of long cond? says it 100 cond states?

5:42 or 1000 or n

5:44 tdammers: I believe cond tests every condition until it finds one that holds

5:44 oddcully: ,(macroexpand '(cond (< 1 2) :a (< 4 3) :b :else :c))

5:44 tdammers: so worst case O(n)

5:44 clojurebot: (if (< 1 2) :a (clojure.core/cond (< 4 3) :b :else :c))

5:45 tdammers: if you have 100 states, using cond is very likely a sign that your design isn't right

6:01 Bronsa: visof: consider using a multimethod

6:18 jeaye: ,(get-in [:a :b :c] [2])

6:18 clojurebot: :c

6:18 jeaye: ,(get-in (:a :b :c) [2])

6:18 clojurebot: nil

6:19 jeaye: Why? :(

6:21 luma: two reasons: (:a :b :c) is a function call that returns :c, so you're calling (get-in :c [2]), which is nil because :c doesn't contain key 2

6:21 jeaye: haha

6:21 luma: secondly, even if you quoted the list, it would still return nil because a list isn't associative

6:22 jeaye: ,(get-in '(:a :b :c) [2])

6:22 clojurebot: nil

6:22 luma: and get-in only works on associative containers

6:22 like vectors and maps

6:22 jeaye: hm

6:22 luma: Thanks.

6:23 bcn-flor: ,(get [:a :b :c] 2)

6:23 clojurebot: :c

6:23 bcn-flor: ,(get (:a :b :c) 2)

6:23 clojurebot: nil

6:23 bcn-flor: The same reason

6:24 jeaye: ,(get '(:a :b :c) 2)

6:24 clojurebot: nil

6:24 PMunch: Hi, I'm trying to use a writer (clojure.java.io) to write data to a socket. It worked fine until I wanted to write IP addresses. It appears to try and parse the string I give it and give me all kinds of weird errors.

6:30 Is this normal behavior?

6:47 xeqi: PMunch: no, I would have expected it just to pass the string onto the wire unless there was some charset problem

6:50 PMunch: xeqi, that's what's so weird. It works if I do (join ", " values) but if I try to do (join "\n" values) it gives me host lookup errors..

7:00 oddcully: are you sure, that your "ip address" is really just a string?

7:09 PMunch: Yup, tried all kinds of wrapping in (str)

7:11 oddcully: but that would also run just toString on some fancy objects?

7:11 well maybe i miss some finer points here

7:16 PMunch: oddcully, I have no idea. Really confused me

8:15 cataska: hi, how can i generate doc from core.async ?

8:59 visof: ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]])

8:59 clojurebot: #'sandbox/foo

8:59 visof: ,foo

8:59 clojurebot: [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]]

9:02 visof: ,(map (fn [x] (let [[a [b] [c]] x] a)) foo)

9:02 clojurebot: (1 2 3)

9:02 opqdonut: ,(map first foo)

9:02 clojurebot: (1 2 3)

9:03 visof: ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo)

9:03 clojurebot: ({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}})

9:04 visof: ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]])

9:04 clojurebot: #'sandbox/foo

9:04 visof: ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo)

9:04 clojurebot: ({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}} {1 {:x (:evil), :y (:devil)}})

9:05 visof: how can i merge the ones which has unique key, like 1 to be

9:05 {1 {:x (:hello :evil) :y (:world :devil)}}

9:05 oddcully: merge-with?

9:06 visof: can i do this in this step ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo) ?

9:06 (cons b []) didn't update the old values it create new

9:06 oddcully: with reduce?

9:09 visof: ,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x {a {:x (cons b []) :y (cons c [])}} ))) [] foo)

9:09 clojurebot: #error {\n :cause "Wrong number of args (2) passed to: core/assoc--4130"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: core/assoc--4130"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.RestFn invoke "RestFn.java" 427]\n [sandbox$eval202$fn__203 invoke "NO_SOURCE_FILE" ...

9:09 visof: ,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x a {:x (cons b []) :y (cons c [])} ))) [] foo)

9:09 clojurebot: #error {\n :cause nil\n :via\n [{:type java.lang.IndexOutOfBoundsException\n :message nil\n :at [clojure.lang.PersistentVector assocN "PersistentVector.java" 187]}]\n :trace\n [[clojure.lang.PersistentVector assocN "PersistentVector.java" 187]\n [clojure.lang.PersistentVector assocN "PersistentVector.java" 21]\n [clojure.lang.APersistentVector assoc "APersistentVector.java" 347]\n [clojure....

9:24 visof: hi

9:24 oddcully: ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]])

9:24 clojurebot: #'sandbox/foo

9:24 oddcully: ,(reduce (fn [m [k [x] [y]]] (merge-with (partial merge-with (partial into)) m {k {:x [x] :y [y]}})) {} foo)

9:24 clojurebot: {1 {:x [:hello :evil], :y [:world :devil]}, 2 {:x [:foo], :y [:bar]}, 3 {:x [:bad], :y [:good]}}

9:25 oddcully: ah (partial into) is a noop

9:27 ,(reduce (fn [m [k x y]] (merge-with (partial merge-with into) m {k {:x x :y y}})) {} foo)

9:27 clojurebot: {1 {:x [:hello :evil], :y [:world :devil]}, 2 {:x [:foo], :y [:bar]}, 3 {:x [:bad], :y [:good]}}

10:31 beaky: hello

10:31 what is the best library for roguelike

10:32 (that can do text-based or tile-based 2d graphics)

10:34 also is there something like hoogle for clojure where i can search for functions by type

10:34 (i want the y combinator in clojure)

10:36 schmir: beaky: conj.io

10:36 beaky: wow conjio is awesome thanks

11:07 visof: ,(apply (partial merge-with +) '({:a 1} {:a 2}) ))

11:07 clojurebot: {:a 3}

11:43 mpereira: beaky: http://stevelosh.com/blog/2012/07/caves-of-clojure-01/

11:50 Glenjamin: what is "Rubyesque culture of brokenness" supposed to mean? :s

11:50 archimedespi: I was wondering the same thing :)

12:02 beaky: wow mpereira thanks

12:15 favetelinguis: is there a way to observe a core.async channel buffer, im trying to debugg but have no insight into what is going on

13:06 wxl: justin_smith: pallet seems like a good option but despite adding it to :user :dependencies in profiles.clj, i still get a ClassNotFoundException trying to exec (alembic.still/distill)

13:06 justin_smith: wxl: pallet/alembic is its own separate lib

13:07 it's from the pallet org, but not part of the pallet framework

13:07 also you need to require alembic.still before you can use distill

13:13 wxl: justin_smith: i was assuming you meant https://github.com/pallet/alembic. is that not the case?

13:13 justin_smith: that's the one

13:14 wxl: well then i guess i'm confused

13:14 justin_smith: did you require the lib before trying to call the function?

13:16 wxl: yeah i've required it to no avail

13:17 justin_smith: can you share your profiles.clj on refheap.com?

13:17 wxl: strange requirement but ok :)

13:17 justin_smith: any paste site would work

13:18 wxl: justin_smith: https://www.refheap.com/111499

13:19 justin_smith: so you get an error if you require alembic.still?

13:20 wxl: the require returns nil, but alembic.still/distill fails

13:21 justin_smith: that means the require succeeded, what does your call look like?

13:21 wxl: (alembic.still/distill '[clj-time "0.10.0"])

13:22 justin_smith: you need another set of square braces there I think

13:22 it's just like the :dependencies part of a project.clj

13:22 wxl: i'd expect that but the README says otherwise

13:22 and indeed no luck there

13:22 justin_smith: what is the specific error you get?

13:22 wxl: with (alembic.still/distill '[[clj-time "0.10.0"]])

13:23 ClassNotFoundException alembic.still java.net.URLClassLoader$1.run (URLClassLoader.java:366)

13:25 justin_smith: wxl: https://www.refheap.com/111500

13:26 WorldsEndless: What's the idiomatic way to unpack (flatten) data? e.g. so that (conj [a b] [c d]) is [a b c d] and not [a b [c d]]?

13:26 justin_smith: ~flatten

13:26 clojurebot: flatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with.

13:26 WorldsEndless: Thanks

13:26 justin_smith: WorldsEndless: in that example, you could just use into instead of conj

13:26 flatten is terrible

13:26 ,(flatten {:a 0})

13:27 clojurebot: ()

13:27 wxl: ah now i get a different exception, justin_smith. one that makes sense. FileNotFoundException with project.clj. the whole point to this was trying to not use a project. i guess that laziness is not worthwhile :)

13:28 justin_smith: wxl: oh, right, it tries to look at your project.clj to see existing deps

13:28 which is silly, I think

13:34 wxl: great works fine a created project. thanks so much!

13:34 justin_smith: wxl: I have a "experimenting" project, with minimum deps, and I pull in other deps with alembic to try things out

13:35 wxl: justin_smith: yeah i see that's what i'll need to do. a wee bit new to clj, so trying to figure out the canonical way to do things.

Logging service provided by n01se.net