#clojure logs

2015-11-09

00:17fluffywafflesany friendly clojure...ists? willing to help me answer a question?
00:17fluffywafflesI have a vector of 1s and 0s and I want to combine the 0s and sum the 1s
00:17fluffywafflesI feel like there should be an easy way to do it, but I'm hitting a wall
00:18fluffywaffleseg, [ 0 1 1 1 0 0 0 1 0 1 1 ] => [ 0 3 0 1 0 2 ]
00:26TEttinger,(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 ])
00:26clojurebot#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...
00:28TEttinger,(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 ])
00:28clojurebot[0 3 0 1 0 ...]
00:28TEttingeryay
00:29TEttingerbut fluffywaffles left
00:29hiredman,(->> [ 0 1 1 1 0 0 0 1 0 1 1 ] (partition-by zero?) (map (partial apply +)))
00:29clojurebot(0 3 0 1 0 ...)
01:05PMunchI'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:
01:06PMunchI have the same kind of signal handling elsewhere in the program and it works fine. But this one instance just refuses to work..
01:11TEttingerPMunch: it doesn't say what fn is getting the wrong args?
01:11TEttingerweird
01:11PMunchTEttinger, it does I just removed it since it's program specific: core/create-node/reify--72/fn--73
01:11TEttingerah ok
01:12TEttingerso this is an interop thing?
01:13PMunchYea, I'm trying to catch SIGINT and SIGTERM to ensure the program shuts down cleanly
01:20TEttingerI'm guessing it might be related to reify maybe needing a this parameter or something like that, I can't remember how reify works
01:20TEttingeror it implicitly being given one, I dunno
01:21PMunchTEttinger, that would be weird since I have the exact same code somewhere else in the program but with different handlers..
01:21PMunchSo I know that the signal handler part should work
01:21PMunchHmm, in fact it does it's first println..
01:22PMunchSo the handler is actually being executed.
01:23PMunchHmm, looking at the function a bit closer it is actually complaining on a swap! call..
01:23TEttingermaybe you don't have an arg when it expects 2, or you're using swap! with a fn that expects no args?
01:24TEttingerreset! will just make an atom equal to a value
01:24tmtwdwhat does the single quote mean when requiring in clojure?
01:24TEttingertmtwd: single quote means "don't run this" basically
01:25tmtwdi mean like this though (require '[honeysql.core :as sql]
01:25PMunchTEttinger, I figured it out. I had made an anonymous function #(...) for the swap and I had forgot to add the % argument.
01:25TEttingerit means you can have symbols like clojure.string without the program trying to figure out whatthey evaluate to
01:25TEttingerahhh
01:25TEttinger,[honeysql.core]
01:26clojurebot#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 [...
01:26TEttinger,'[honeysql.core]
01:26clojurebot[honeysql.core]
01:26TEttingertmtwd, 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
01:27TEttingerin the first example, it tries to resolve what honeysql.core is
01:27tmtwdbut then I get this error ava.lang.Exception: Found lib name 'honeysql.core' containing period with prefix 'quote'.
01:27TEttingeryou don't need the quote when using :require in the ns macro, which is usually the first thing in a file
01:28tmtwdbut then I get this error Could not locate honeysql/core__init.class or honeysql/core.clj
01:28tmtwdyes hsql is installed
01:28tmtwdin project.clj
01:28TEttinger,(require '[clojure.string :as st])
01:28clojurebotnil
01:29TEttinger,(st/join [1 2 3])
01:29clojurebot"123"
01:29tmtwdbut I have the colon in front of require
01:29tmtwd,(require [clojure.string :as s])
01:29TEttingerah, is this in the ns section thing?
01:29clojurebot#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\...
01:29tmtwdyes
01:30TEttingerthen you don't use the quote
01:30tmtwd,(:require [clojure.string :as s])
01:30clojurebot#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\...
01:30TEttinger:require only makes sense in (ns)
01:30tmtwdhttp://pastebin.com/txMHwZHw
01:30TEttingerit's part of an instruction to the macro called "ns"
01:31tmtwdI'm trying to do this
01:31tmtwdbut I get a Could not locate honeysql/core__init.class or honeysql/core.clj error
01:32tmtwdhuh let me try a lein clean
01:33TEttingergood idea
01:36tmtwdyeah, isn't working, and its in the m2 repo directory too from which I draw all my libraries
01:48oddcullytmtwd: you have that dep in :dependencies [[honeysql "<ver>"]]?
01:48oddcullyit shows in lein deps :tree ?
01:48oddcullyyou are trying to use it in a .clj file?
02:40jeayeWhat's a cleaner way of saying (rest (rest (rest foo)))?
02:40jeayeAh, drop!
02:41mavbozonthrest, nthnext
02:42jeayeGood to know; drop will work here, too.
03:08dstocktonto anyone using spacemacs, why is the line highlighting on the default theme so awful (yellow, can't read the text)?
04:13kungiwhy does (binding [foo "bar"] (map f coll)) not bind foo in f?
04:15Bronsa`kungi: dynamic binding and lazyness don't mix too good together
04:17kungiBronsa: what about (binding [foo ...] (map (partial f foo) coll))
04:18Bronsayes that would work
04:19Bronsaassuming your f goes from (fn [.. el] ..) to (fn [foo .. el] ..)
04:20kungiBronsa: it does :-)
04:22amalloywell but there's no reason to use binding there. just use let
04:23kungiamalloy: 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.
04:23baz_morning, is it possible to access the project map while defining an alias?
04:24baz_in this particular case I would like to access the project version
04:24kungibaz_: You can slurp in the project.clj and extract the version.
04:24amalloyno, in the last example you pasted a binding is exactly the same as a let
04:24kungibaz_: At least that is what I am doing
04:25amalloyor indeed using neither at all and just (partial f ...)
04:25baz_kungi: thanks, will try that
04:39baz_kungi: :project/version also works in aliases
04:39baz_kungi: found the example project.clj, obviously :P
04:39baz_*found in
05:09lumabecause map returns a lazy sequence, so when the sequence is realized, it's not inside the binding anymore
05:09lumaoops, i was scrolled up
05:09lumasorry
05:41visofhi guys
05:41visofwhat is the performace of long cond? says it 100 cond states?
05:42visofor 1000 or n
05:44tdammersI believe cond tests every condition until it finds one that holds
05:44oddcully,(macroexpand '(cond (< 1 2) :a (< 4 3) :b :else :c))
05:44tdammersso worst case O(n)
05:44clojurebot(if (< 1 2) :a (clojure.core/cond (< 4 3) :b :else :c))
05:45tdammersif you have 100 states, using cond is very likely a sign that your design isn't right
06:01Bronsavisof: consider using a multimethod
06:18jeaye,(get-in [:a :b :c] [2])
06:18clojurebot:c
06:18jeaye,(get-in (:a :b :c) [2])
06:18clojurebotnil
06:19jeayeWhy? :(
06:21lumatwo 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
06:21jeayehaha
06:21lumasecondly, even if you quoted the list, it would still return nil because a list isn't associative
06:22jeaye,(get-in '(:a :b :c) [2])
06:22clojurebotnil
06:22lumaand get-in only works on associative containers
06:22lumalike vectors and maps
06:22jeayehm
06:22jeayeluma: Thanks.
06:23bcn-flor,(get [:a :b :c] 2)
06:23clojurebot:c
06:23bcn-flor,(get (:a :b :c) 2)
06:23clojurebotnil
06:23bcn-florThe same reason
06:24jeaye,(get '(:a :b :c) 2)
06:24clojurebotnil
06:24PMunchHi, 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.
06:30PMunchIs this normal behavior?
06:47xeqiPMunch: no, I would have expected it just to pass the string onto the wire unless there was some charset problem
06:50PMunchxeqi, 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..
07:00oddcullyare you sure, that your "ip address" is really just a string?
07:09PMunchYup, tried all kinds of wrapping in (str)
07:11oddcullybut that would also run just toString on some fancy objects?
07:11oddcullywell maybe i miss some finer points here
07:16PMunchoddcully, I have no idea. Really confused me
08:15cataskahi, how can i generate doc from core.async ?
08:59visof,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]])
08:59clojurebot#'sandbox/foo
08:59visof,foo
08:59clojurebot[[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]]
09:02visof,(map (fn [x] (let [[a [b] [c]] x] a)) foo)
09:02clojurebot(1 2 3)
09:02opqdonut,(map first foo)
09:02clojurebot(1 2 3)
09:03visof,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo)
09:03clojurebot({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}})
09:04visof,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]])
09:04clojurebot#'sandbox/foo
09:04visof,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo)
09:04clojurebot({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}} {1 {:x (:evil), :y (:devil)}})
09:05visofhow can i merge the ones which has unique key, like 1 to be
09:05visof{1 {:x (:hello :evil) :y (:world :devil)}}
09:05oddcullymerge-with?
09:06visofcan i do this in this step ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo) ?
09:06visof(cons b []) didn't update the old values it create new
09:06oddcullywith reduce?
09:09visof,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x {a {:x (cons b []) :y (cons c [])}} ))) [] foo)
09:09clojurebot#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" ...
09:09visof,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x a {:x (cons b []) :y (cons c [])} ))) [] foo)
09:09clojurebot#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....
09:24visofhi
09:24oddcully,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]])
09:24clojurebot#'sandbox/foo
09:24oddcully,(reduce (fn [m [k [x] [y]]] (merge-with (partial merge-with (partial into)) m {k {:x [x] :y [y]}})) {} foo)
09:24clojurebot{1 {:x [:hello :evil], :y [:world :devil]}, 2 {:x [:foo], :y [:bar]}, 3 {:x [:bad], :y [:good]}}
09:25oddcullyah (partial into) is a noop
09:27oddcully,(reduce (fn [m [k x y]] (merge-with (partial merge-with into) m {k {:x x :y y}})) {} foo)
09:27clojurebot{1 {:x [:hello :evil], :y [:world :devil]}, 2 {:x [:foo], :y [:bar]}, 3 {:x [:bad], :y [:good]}}
10:31beakyhello
10:31beakywhat is the best library for roguelike
10:32beaky(that can do text-based or tile-based 2d graphics)
10:34beakyalso is there something like hoogle for clojure where i can search for functions by type
10:34beaky(i want the y combinator in clojure)
10:36schmirbeaky: conj.io
10:36beakywow conjio is awesome thanks
11:07visof,(apply (partial merge-with +) '({:a 1} {:a 2}) ))
11:07clojurebot{:a 3}
11:43mpereirabeaky: http://stevelosh.com/blog/2012/07/caves-of-clojure-01/
11:50Glenjaminwhat is "Rubyesque culture of brokenness" supposed to mean? :s
11:50archimedespiI was wondering the same thing :)
12:02beakywow mpereira thanks
12:15favetelinguisis there a way to observe a core.async channel buffer, im trying to debugg but have no insight into what is going on
13:06wxljustin_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:06justin_smithwxl: pallet/alembic is its own separate lib
13:07justin_smithit's from the pallet org, but not part of the pallet framework
13:07justin_smithalso you need to require alembic.still before you can use distill
13:13wxljustin_smith: i was assuming you meant https://github.com/pallet/alembic. is that not the case?
13:13justin_smiththat's the one
13:14wxlwell then i guess i'm confused
13:14justin_smithdid you require the lib before trying to call the function?
13:16wxlyeah i've required it to no avail
13:17justin_smithcan you share your profiles.clj on refheap.com?
13:17wxlstrange requirement but ok :)
13:17justin_smithany paste site would work
13:18wxljustin_smith: https://www.refheap.com/111499
13:19justin_smithso you get an error if you require alembic.still?
13:20wxlthe require returns nil, but alembic.still/distill fails
13:21justin_smiththat means the require succeeded, what does your call look like?
13:21wxl(alembic.still/distill '[clj-time "0.10.0"])
13:22justin_smithyou need another set of square braces there I think
13:22justin_smithit's just like the :dependencies part of a project.clj
13:22wxli'd expect that but the README says otherwise
13:22wxland indeed no luck there
13:22justin_smithwhat is the specific error you get?
13:22wxlwith (alembic.still/distill '[[clj-time "0.10.0"]])
13:23wxlClassNotFoundException alembic.still java.net.URLClassLoader$1.run (URLClassLoader.java:366)
13:25justin_smithwxl: https://www.refheap.com/111500
13:26WorldsEndlessWhat'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:26justin_smith~flatten
13:26clojurebotflatten 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:26WorldsEndlessThanks
13:26justin_smithWorldsEndless: in that example, you could just use into instead of conj
13:26justin_smithflatten is terrible
13:26justin_smith,(flatten {:a 0})
13:27clojurebot()
13:27wxlah 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:28justin_smithwxl: oh, right, it tries to look at your project.clj to see existing deps
13:28justin_smithwhich is silly, I think
13:34wxlgreat works fine a created project. thanks so much!
13:34justin_smithwxl: I have a "experimenting" project, with minimum deps, and I pull in other deps with alembic to try things out
13:35wxljustin_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.