#clojure log - Nov 29 2015

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

0:36 TEttinger: ,(expt 2N 18446744073709551616N)

0:36 clojurebot: #error {\n :cause "Unable to resolve symbol: expt in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: expt 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: expt in this co...

0:37 TEttinger: right, I imported the numeric tower lib

0:39 I think that's uh a rather large number

0:46 Jinxit: is there any good online quick start to clojure? I'm familiar with functional programming

0:46 but not really any lisps

1:05 TEttinger: Jinxit: brave clojure, 4clojure exercises, clojuredoc

1:05 ~brave clojure

1:05 clojurebot: Titim gan éirí ort.

1:05 TEttinger: clojurebot: brave is http://www.braveclojure.com/

1:05 clojurebot: c'est bon!

1:06 justin_smith: Jinxit: also, http://conj.io is a good reference to the core language of clojure, and most functions there should be somewhat familiar if you have used functional languages

1:06 TEttinger: good ol' grimoire

1:07 Jinxit: alright, thanks all

2:05 Seraf: Hello everyone. I'm a bit loss: I'm trying to group-by date my results : http://pastebin.com/BhMLZXJw I'm using cljs-time. The problem is that I can't group-by directly on my data as the datetime is too much precise so I would like to convert it to YYYY-MM-DD to have a "logic" group-by. So I need to transform my map before applying a group by on it (but I also don't want to loose the original data as I would like to use it).

2:06 I tried a :date_finished on the group-by, but if I apply my cljs-time function on the keyword, it isn't a function anymore then it doesn't work :(

3:51 douglarek: how can i stop an execution in cider repl ?

3:51 such as : i entered (cycle [1])

3:54 Seraf: Hello everyone. I'm a bit loss: I'm trying to group-by date my results : http://pastebin.com/BhMLZXJw I'm using cljs-time. The problem is that I can't group-by directly on my data as the datetime is too much precise so I would like to convert it to YYYY-MM-DD to have a "logic" group-by. So I need to transform my map before applying a group by on it (but I also don't want to loose the original date as I would like to use it further).

4:43 ben_vulpes: how would one go about passing &args to a downstream function in such a way that it doesn't wrap them in a list itself?

4:55 TEttinger: ben_vulpes: apply

4:56 ,((fn [& args] (clojure.string/join "," args)) "hey" "clojure" "people")

4:56 clojurebot: "hey,clojure,people"

4:57 TEttinger: ,((fn [& args] (apply str args)) "hey" "clojure" "people")

4:57 clojurebot: "heyclojurepeople"

4:57 ben_vulpes: TEttinger: myeah, i got hung up on non-optional args.

4:58 was shooting for (apply (partial my-func arg1) [:optional :args])

4:59 TEttinger: do what I do in this situation

4:59 hope justin_smith is awake

5:00 ben_vulpes: hahahaha

5:00 's not a big deal.

5:38 Glenjamin: Seraf: group-by takes a function, have that function do the date formatting

5:54 Seraf: Glenjamin, thanks for the answer, I finally found a solution, it's working well

6:59 donbonifacio: why is equality with persistent data structures so efficient? Why is there no need to perform a deep compare?

7:35 kungi: donbonifacio: because they are immutable. therefore no deep compares are required

7:36 donbonifacio: I'm checking out the core, and deep compares may happen

7:36 it's very optimized true, but it can happen

7:58 TimMc: One really simple case is where you pass someone a nested map, they may or may not do something to it, and they pass you back another version of it and you want to compare some of the submaps.

7:58 or just the whole thing, I guess

7:58 If a map hasn't been altered, the object identity is the same, so an equality check is really fast.

7:59 In Java-land, you'd probably want to do a deep copy to make sure mutation is controlled, and then you'd lose that shortcut.

8:03 beaky: hello

8:03 how do i printf a list

8:03 or vector or map

8:05 TimMc: beaky: Not re what precisely you're having trouble with. What's a sample input and output that you want?

8:05 *Not sure

8:05 beaky: ,(printf "%s\n" [])

8:05 i wat that to be []

8:05 clojurebot: []\n

8:05 beaky: oh

8:05 nvm :D

8:05 ,(printf "%s\n" [1 2 3])

8:05 clojurebot: [1 2 3]\n

8:13 TimMc: beaky: Do you know the pr/print distinction?

8:22 beaky: TimMc: no whats the diference

8:22 ,(pr [1 2 3])

8:22 clojurebot: [1 2 3]

8:23 beaky: ,(pr "1 2 3")

8:23 clojurebot: "1 2 3"

8:23 jeaye: ^ that

8:23 beaky: (print "1 2 3")

8:23 ,(print "1 2 3")

8:23 clojurebot: 1 2 3

8:23 beaky: ah

8:24 no " in print

8:27 jonathanj: can i iterate an Iterable<X> in Clojure?

8:30 Bronsa: you can reduce over it

8:59 justin_smith: ben_vulpes: (apply str "a" ["b" "c"])

8:59 ,(apply str "a" ["b" "c"])

8:59 clojurebot: "abc"

9:11 TimMc: beaky: In general, print prints the contents of data, and pr prints in a way that can be read back through read-string.

9:12 Strings are the only thing that comes to mind at the moment as printing differently.

9:13 beaky: It's not just the quotes; "a\nb" will print as a and b on two lines but pr as six chars: "a\nb"

9:14 justin_smith: ,(pr (map char (range)))

9:14 clojurebot: (\

9:14 justin_smith: ,(print (map char (range)))

9:14 clojurebot: (

9:14 justin_smith: hmmm

9:15 ,(print (map char (range (int \a) (int \z)))

9:15 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

9:15 justin_smith: ,(print (map char (range (int \a) (int \z))))

9:15 clojurebot: (a b c d e ...)

9:15 justin_smith: ,(pr (map char (range (int \a) (int \z))))

9:15 clojurebot: (\a \b \c \d \e ...)

9:15 justin_smith: ,(str (map char (range (int \a) (int \z))))

9:15 clojurebot: "clojure.lang.LazySeq@9013fb8c"

9:16 justin_smith: sad trombone

9:20 Bronsa`: j

9:24 beaky: ah

9:30 wmealing: this is probably a rookie mistake, I'm a little stuck on how to ensure that when mapping over and ordered list, that the returned data is in the same order.. my example is here

9:30 http://hastebin.com/cihewahuhu.pl

9:31 i had tried with an array-map (see line 16)

9:31 justin_smith: wmealing: "Application Error"

9:31 wmealing: map doesn't ever change the order relative to the input

9:32 wmealing: it's not map changing the order, it's array-map

9:32 wmealing: ok, so what.. or how should I be doing that ?

9:33 i'm 100% sure this is my fault.. i know that

9:33 justin_smith: wmealing: if you need the data to be ordered, you shouldn't be using a hash-map or array-map. There is an insertion ordered map from flatland, flatland/ordered-map iirc.

9:34 wmealing: I was wrong, it's amalloy/ordered https://github.com/amalloy/ordered

9:34 wmealing: it might seem like array-map would have preserved the order, but if you conj onto an array-map of a certain size, it returns a hash-map

9:35 wmealing: which is likely what i'm seeing there

9:35 justin_smith: yes, that is exactly what's happening - note how the processing happens in order, verified by your printing

9:35 it's the storage that goes out of order

9:35 * wmealing nods

9:36 wmealing: is there a better/alternative way to be doing what i'm doing

9:36 i guess i could just pull them out in order when i extract them from the map

9:36 justin_smith: wmealing: an ordered map makes sense if you want to preserve insertion order and also look things up by key

9:37 wmealing: thanks justin_smith.

9:37 justin_smith: wmealing: another alternative would be mapping the months to indexes in a vector via a hash-map, then putting the data in a vector by those indexes, but of course that is less convenient and direct

9:38 wmealing: right. just one of the choices i have to make

10:26 Glenjamin: i'd probably suggest a sorted-map here

10:26 rather than relying on correct insertion, since the keys do have a well-defined sort order

10:28 some combination of (sorted-map-by), a map of month->index and (compare) would do it

10:36 jonathanj: is there some way i can use with-open with a collection of streams?

10:37 something like: (with-open [streams (fetch-multiple [uri1 uri2 uri3])] ...)

10:49 justin_smith: jonathanj: a multi-arity with-open that expands to nested with-open calls would be a nice intermediate macro writing challenge

11:06 jonathanj: nested?

11:07 i'm not sure they have to be nested, they just have to be unrolled, surely?

11:07 justin_smith: with-open manages a single stream

11:07 what do you mean by unrolled?

11:07 jonathanj: with-open calls close on all of the bindings

11:08 justin_smith: (doc with-open)

11:08 clojurebot: "([bindings & body]); bindings => [name init ...] Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (.close name) on each name in reverse order."

11:08 justin_smith: oh, it takes multiple streams anyway, never mind

11:09 so no, you can't do it with a macro

11:09 unless the collection is known at macro expansion time, which is part of the compilation process

11:09 so you could do it with eval, but that's gross

12:19 Glenjamin: $source with-open

13:32 justin_smith: Glenjamin: I could see doing it with a recursive function that takes streams as a list and an N arg function to apply to the streams, and for each recursive call it creates a try/catch/finally for the next stream and adds it to the list for applying...

15:35 devn_: I can't brane good today.

15:36 devn: I am using environ, and I have a function that pulls values out of the environ map.

15:37 This function raises if a particular configuration value is not found.

15:37 I'm thinking that I'd like to make a new type of map that does this, so I don't have to call the function

15:38 so (get environ-map :foo) will throw if :foo doesn't exist

15:38 justin_smith: easier to write the alternate get, but sure

15:38 devn: well, i'd like to destructure, for example

15:39 (let [{:keys [a b c]} environ-map] ...)

15:39 justin_smith: what's the best way to do what im trying to do here? do i want to reify and define get on this particular map instance?

15:39 or?

15:39 clojurebot: or is there another way to upload it

15:41 justin_smith: devn: yeah, you could use reify and implement all the relevant methods, referring to the original object for everything but get, where you have the throw?

15:41 devn: but maybe it would be simpler to use prismatic/schema to check the map when it's created?

15:43 devn: justin_smith: maybe...

15:43 or maybe try out structural typing

15:43 https://github.com/marick/structural-typing

15:44 justin_smith: when you say "all the relevant methods"

15:44 justin_smith: devn: interesting, looks like it tries to do some of the same stuff prismatic/schema tries to do

15:45 devn: i should just need a couple of arities for `get` (m k) (m k not-found), and `get-in` right?

15:45 justin_smith: devn: by that I mean check out (supers {}) or (supers (class {})) or whatever it is, and get all their methods, and implement them all by delegating to your hash-map

15:45 or just implement only and exactly the methods you plan on anyone ever calling, I guess

15:46 devn: yeah, that seems gross, ive done that before by using potemkin

15:46 to use deftypefn i think it's called

15:47 justin_smith: i think i like this structural typing business quite a bit

16:05 kenrestivo: is there a cond with fallthrough?

16:05 ah, nevermind :else

Logging service provided by n01se.net