2015-11-09
| 00:17 | fluffywaffles | any friendly clojure...ists? willing to help me answer a question? |
| 00:17 | fluffywaffles | I have a vector of 1s and 0s and I want to combine the 0s and sum the 1s |
| 00:17 | fluffywaffles | I feel like there should be an easy way to do it, but I'm hitting a wall |
| 00:18 | fluffywaffles | eg, [ 0 1 1 1 0 0 0 1 0 1 1 ] => [ 0 3 0 1 0 2 ] |
| 00: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 ]) |
| 00: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... |
| 00: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 ]) |
| 00:28 | clojurebot | [0 3 0 1 0 ...] |
| 00:28 | TEttinger | yay |
| 00:29 | TEttinger | but fluffywaffles left |
| 00:29 | hiredman | ,(->> [ 0 1 1 1 0 0 0 1 0 1 1 ] (partition-by zero?) (map (partial apply +))) |
| 00:29 | clojurebot | (0 3 0 1 0 ...) |
| 01: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: |
| 01:06 | PMunch | I have the same kind of signal handling elsewhere in the program and it works fine. But this one instance just refuses to work.. |
| 01:11 | TEttinger | PMunch: it doesn't say what fn is getting the wrong args? |
| 01:11 | TEttinger | weird |
| 01:11 | PMunch | TEttinger, it does I just removed it since it's program specific: core/create-node/reify--72/fn--73 |
| 01:11 | TEttinger | ah ok |
| 01:12 | TEttinger | so this is an interop thing? |
| 01:13 | PMunch | Yea, I'm trying to catch SIGINT and SIGTERM to ensure the program shuts down cleanly |
| 01: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 |
| 01:20 | TEttinger | or it implicitly being given one, I dunno |
| 01:21 | PMunch | TEttinger, that would be weird since I have the exact same code somewhere else in the program but with different handlers.. |
| 01:21 | PMunch | So I know that the signal handler part should work |
| 01:21 | PMunch | Hmm, in fact it does it's first println.. |
| 01:22 | PMunch | So the handler is actually being executed. |
| 01:23 | PMunch | Hmm, looking at the function a bit closer it is actually complaining on a swap! call.. |
| 01: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? |
| 01:24 | TEttinger | reset! will just make an atom equal to a value |
| 01:24 | tmtwd | what does the single quote mean when requiring in clojure? |
| 01:24 | TEttinger | tmtwd: single quote means "don't run this" basically |
| 01:25 | tmtwd | i mean like this though (require '[honeysql.core :as sql] |
| 01:25 | PMunch | TEttinger, I figured it out. I had made an anonymous function #(...) for the swap and I had forgot to add the % argument. |
| 01:25 | TEttinger | it means you can have symbols like clojure.string without the program trying to figure out whatthey evaluate to |
| 01:25 | TEttinger | ahhh |
| 01:25 | TEttinger | ,[honeysql.core] |
| 01: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 [... |
| 01:26 | TEttinger | ,'[honeysql.core] |
| 01:26 | clojurebot | [honeysql.core] |
| 01: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 |
| 01:27 | TEttinger | in the first example, it tries to resolve what honeysql.core is |
| 01:27 | tmtwd | but then I get this error ava.lang.Exception: Found lib name 'honeysql.core' containing period with prefix 'quote'. |
| 01:27 | TEttinger | you don't need the quote when using :require in the ns macro, which is usually the first thing in a file |
| 01:28 | tmtwd | but then I get this error Could not locate honeysql/core__init.class or honeysql/core.clj |
| 01:28 | tmtwd | yes hsql is installed |
| 01:28 | tmtwd | in project.clj |
| 01:28 | TEttinger | ,(require '[clojure.string :as st]) |
| 01:28 | clojurebot | nil |
| 01:29 | TEttinger | ,(st/join [1 2 3]) |
| 01:29 | clojurebot | "123" |
| 01:29 | tmtwd | but I have the colon in front of require |
| 01:29 | tmtwd | ,(require [clojure.string :as s]) |
| 01:29 | TEttinger | ah, is this in the ns section thing? |
| 01: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\... |
| 01:29 | tmtwd | yes |
| 01:30 | TEttinger | then you don't use the quote |
| 01:30 | tmtwd | ,(:require [clojure.string :as s]) |
| 01: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\... |
| 01:30 | TEttinger | :require only makes sense in (ns) |
| 01:30 | tmtwd | http://pastebin.com/txMHwZHw |
| 01:30 | TEttinger | it's part of an instruction to the macro called "ns" |
| 01:31 | tmtwd | I'm trying to do this |
| 01:31 | tmtwd | but I get a Could not locate honeysql/core__init.class or honeysql/core.clj error |
| 01:32 | tmtwd | huh let me try a lein clean |
| 01:33 | TEttinger | good idea |
| 01:36 | tmtwd | yeah, isn't working, and its in the m2 repo directory too from which I draw all my libraries |
| 01:48 | oddcully | tmtwd: you have that dep in :dependencies [[honeysql "<ver>"]]? |
| 01:48 | oddcully | it shows in lein deps :tree ? |
| 01:48 | oddcully | you are trying to use it in a .clj file? |
| 02:40 | jeaye | What's a cleaner way of saying (rest (rest (rest foo)))? |
| 02:40 | jeaye | Ah, drop! |
| 02:41 | mavbozo | nthrest, nthnext |
| 02:42 | jeaye | Good to know; drop will work here, too. |
| 03:08 | dstockton | to anyone using spacemacs, why is the line highlighting on the default theme so awful (yellow, can't read the text)? |
| 04:13 | kungi | why does (binding [foo "bar"] (map f coll)) not bind foo in f? |
| 04:15 | Bronsa` | kungi: dynamic binding and lazyness don't mix too good together |
| 04:17 | kungi | Bronsa: what about (binding [foo ...] (map (partial f foo) coll)) |
| 04:18 | Bronsa | yes that would work |
| 04:19 | Bronsa | assuming your f goes from (fn [.. el] ..) to (fn [foo .. el] ..) |
| 04:20 | kungi | Bronsa: it does :-) |
| 04:22 | amalloy | well but there's no reason to use binding there. just use let |
| 04: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. |
| 04:23 | baz_ | morning, is it possible to access the project map while defining an alias? |
| 04:24 | baz_ | in this particular case I would like to access the project version |
| 04:24 | kungi | baz_: You can slurp in the project.clj and extract the version. |
| 04:24 | amalloy | no, in the last example you pasted a binding is exactly the same as a let |
| 04:24 | kungi | baz_: At least that is what I am doing |
| 04:25 | amalloy | or indeed using neither at all and just (partial f ...) |
| 04:25 | baz_ | kungi: thanks, will try that |
| 04:39 | baz_ | kungi: :project/version also works in aliases |
| 04:39 | baz_ | kungi: found the example project.clj, obviously :P |
| 04:39 | baz_ | *found in |
| 05:09 | luma | because map returns a lazy sequence, so when the sequence is realized, it's not inside the binding anymore |
| 05:09 | luma | oops, i was scrolled up |
| 05:09 | luma | sorry |
| 05:41 | visof | hi guys |
| 05:41 | visof | what is the performace of long cond? says it 100 cond states? |
| 05:42 | visof | or 1000 or n |
| 05:44 | tdammers | I believe cond tests every condition until it finds one that holds |
| 05:44 | oddcully | ,(macroexpand '(cond (< 1 2) :a (< 4 3) :b :else :c)) |
| 05:44 | tdammers | so worst case O(n) |
| 05:44 | clojurebot | (if (< 1 2) :a (clojure.core/cond (< 4 3) :b :else :c)) |
| 05:45 | tdammers | if you have 100 states, using cond is very likely a sign that your design isn't right |
| 06:01 | Bronsa | visof: consider using a multimethod |
| 06:18 | jeaye | ,(get-in [:a :b :c] [2]) |
| 06:18 | clojurebot | :c |
| 06:18 | jeaye | ,(get-in (:a :b :c) [2]) |
| 06:18 | clojurebot | nil |
| 06:19 | jeaye | Why? :( |
| 06: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 |
| 06:21 | jeaye | haha |
| 06:21 | luma | secondly, even if you quoted the list, it would still return nil because a list isn't associative |
| 06:22 | jeaye | ,(get-in '(:a :b :c) [2]) |
| 06:22 | clojurebot | nil |
| 06:22 | luma | and get-in only works on associative containers |
| 06:22 | luma | like vectors and maps |
| 06:22 | jeaye | hm |
| 06:22 | jeaye | luma: Thanks. |
| 06:23 | bcn-flor | ,(get [:a :b :c] 2) |
| 06:23 | clojurebot | :c |
| 06:23 | bcn-flor | ,(get (:a :b :c) 2) |
| 06:23 | clojurebot | nil |
| 06:23 | bcn-flor | The same reason |
| 06:24 | jeaye | ,(get '(:a :b :c) 2) |
| 06:24 | clojurebot | nil |
| 06: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. |
| 06:30 | PMunch | Is this normal behavior? |
| 06:47 | xeqi | PMunch: no, I would have expected it just to pass the string onto the wire unless there was some charset problem |
| 06: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.. |
| 07:00 | oddcully | are you sure, that your "ip address" is really just a string? |
| 07:09 | PMunch | Yup, tried all kinds of wrapping in (str) |
| 07:11 | oddcully | but that would also run just toString on some fancy objects? |
| 07:11 | oddcully | well maybe i miss some finer points here |
| 07:16 | PMunch | oddcully, I have no idea. Really confused me |
| 08:15 | cataska | hi, how can i generate doc from core.async ? |
| 08:59 | visof | ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]]) |
| 08:59 | clojurebot | #'sandbox/foo |
| 08:59 | visof | ,foo |
| 08:59 | clojurebot | [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]]] |
| 09:02 | visof | ,(map (fn [x] (let [[a [b] [c]] x] a)) foo) |
| 09:02 | clojurebot | (1 2 3) |
| 09:02 | opqdonut | ,(map first foo) |
| 09:02 | clojurebot | (1 2 3) |
| 09:03 | visof | ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo) |
| 09:03 | clojurebot | ({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}}) |
| 09:04 | visof | ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]]) |
| 09:04 | clojurebot | #'sandbox/foo |
| 09:04 | visof | ,(map (fn [x] (let [[a [b] [c]] x] {a {:x (cons b []) :y (cons c [])}})) foo) |
| 09:04 | clojurebot | ({1 {:x (:hello), :y (:world)}} {2 {:x (:foo), :y (:bar)}} {3 {:x (:bad), :y (:good)}} {1 {:x (:evil), :y (:devil)}}) |
| 09:05 | visof | how can i merge the ones which has unique key, like 1 to be |
| 09:05 | visof | {1 {:x (:hello :evil) :y (:world :devil)}} |
| 09:05 | oddcully | merge-with? |
| 09: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) ? |
| 09:06 | visof | (cons b []) didn't update the old values it create new |
| 09:06 | oddcully | with reduce? |
| 09:09 | visof | ,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x {a {:x (cons b []) :y (cons c [])}} ))) [] foo) |
| 09: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" ... |
| 09:09 | visof | ,(reduce (fn [x y] (let [[a [b] [c]] y] (assoc x a {:x (cons b []) :y (cons c [])} ))) [] foo) |
| 09: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.... |
| 09:24 | visof | hi |
| 09:24 | oddcully | ,(def foo [[1 [:hello] [:world]] [2 [:foo] [:bar]] [3 [:bad] [:good]] [1 [:evil] [:devil]]]) |
| 09:24 | clojurebot | #'sandbox/foo |
| 09:24 | oddcully | ,(reduce (fn [m [k [x] [y]]] (merge-with (partial merge-with (partial into)) m {k {:x [x] :y [y]}})) {} foo) |
| 09:24 | clojurebot | {1 {:x [:hello :evil], :y [:world :devil]}, 2 {:x [:foo], :y [:bar]}, 3 {:x [:bad], :y [:good]}} |
| 09:25 | oddcully | ah (partial into) is a noop |
| 09:27 | oddcully | ,(reduce (fn [m [k x y]] (merge-with (partial merge-with into) m {k {:x x :y y}})) {} foo) |
| 09: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 | beaky | what is the best library for roguelike |
| 10:32 | beaky | (that can do text-based or tile-based 2d graphics) |
| 10:34 | beaky | also is there something like hoogle for clojure where i can search for functions by type |
| 10:34 | beaky | (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 | justin_smith | it's from the pallet org, but not part of the pallet framework |
| 13:07 | justin_smith | 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 | justin_smith | 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 | wxl | 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 | wxl | 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 | justin_smith | flatten is terrible |
| 13:26 | justin_smith | ,(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 | justin_smith | 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. |