#clojure log - Apr 24 2011

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

0:00 KirinDave: The idea is 2 weeks arcs. Kids are signing up for it as opposed to a hs class where they get funneled in. Most have at least dicked around with javascript.

0:01 amalloy: seancorfield__: go try it out. we luvs new users

0:01 technomancy: huh; taking a peek

0:02 KirinDave: heh; have you seen the Clojure peepcode?

0:02 it's a lot like that.

0:02 KirinDave: Yes.

0:02 Actually

0:02 There are 3 ongoing projects

0:02 In this class

0:02 I hope that this class could get this project to a state where multiple people could log in

0:03 technomancy: yeah, that's a simple way to get people thinking about consistency and concurrency

0:03 KirinDave: In this case, we're covering file i/o, basic data structures, and data driven programming.

0:05 technomancy: sounds like fun

0:05 I have a hard time gauging what kids can pull off, but provided the right level of hints I'm sure it would work.

0:05 KirinDave: Yeah

0:06 I will just be in to help out every 2 weeks.

0:17 brunoalfirevic: help /bar

0:17 exit

0:53 seancorfield__: amalloy: i just did the first 40 4clojure problems :)

0:54 amalloy: seancorfield__: nice! glad you found them entertaining. any suggestions for new problems, or improvements in general? also, we welcome contributors at https://github.com/dbyrne/4clojure/

0:56 seancorfield__: the first one was so easy i got it wrong several times thinking it was asking something harder :)

0:56 amalloy: haha

0:57 seancorfield__: then it was a pretty easy run for a while and then suddenly things seemed to get harder than they looked

0:57 when i got to 41 my first few ideas at a solution were horribly complex

0:58 amalloy: seancorfield__: yeah, i was really thrown by how hard some of them wound up being

0:59 i think it may have been 41 that got me as well. i was the one who wrote problem 43, and i was blown away by a solution, much cleverer than mine, that got tweeted

1:00 oh no, 44 was the hard one

1:00 seancorfield__: so i stopped to take a break... i'm sure i can figure out a simpler solution soon :)

2:43 joshua__: Whats the Clojure equivalent of writing a nested list comprehension?

2:43 amalloy: joshua__: for supports nesting

2:43 &(for [x (range 5) y (range x)] [x y])

2:43 sexpbot: ⟹ ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3])

2:44 joshua__: amalloy, Nice. Thanks.

2:44 amalloy: note also the :when, :while, and :let keywords in (for...)

3:03 joshua__: amalloy, thanks amalloy, got it working =) https://gist.github.com/939383

3:08 Reading up on for has been interesting. I didn't realize how powerful it was: http://www.bestinclass.dk/index.clj/2010/02/clojure-list-comprehension.html

3:09 amalloy: it's pretty massive

3:09 not quite as featured as CL's loop, but it doesn't have to be in a functional language

3:09 joshua__: I find it a little funny that I've never had to use it before now.. =p

3:11 amalloy: yeah you have. you've just used something else instead

3:13 eg, ##(into {} (map (fn [[k v]] [v k]) {1 2 3 4 5 6})) should really be ##(into {} (for [[k v] {1 2 3 4 5 6}] [v k]))

3:13 sexpbot: (into {} (map (fn [[k v]] [v k]) {1 2, 3... ⟹ {2 1, 4 3, 6 5}

3:13 (into {} (for [[k v] {1 2, 3 4, 5 6}] [v... ⟹ {2 1, 4 3, 6 5}

3:18 amalloy: joshua__: ^

3:21 joshua__: amalloy, Thats what I meant, I think. I've been able to use other things to ape the functionality with some ease.

3:52 amalloy: joshua__: ##(class #{1 2 3})

3:52 sexpbot: ⟹ clojure.lang.PersistentHashSet

3:55 matthias__: amalloy, were you the guy who made 4clojure.com?

3:55 amalloy: matthias__: i was the second person to join the 4clojure team

3:55 matthias__: ah

3:55 amalloy: credit for the idea and the first draft goes to dbyrne

3:56 matthias__: i just finished one of the problems and it seems to have disappeared D:

3:56 it was the one were interpose was forbidden. or was it interspose?

3:57 also, one of the ones i had already solved is now unsolved (the reverse one). although i might have messed up the loging in

3:57 amalloy: matthias__: the problem disappeared, or your solution?

3:57 matthias__: the problem. i cant see it in the list anymore

3:57 amalloy: matthias__: try typing "inter" into the search bar at the top

3:57 matthias__: oh

3:57 its on page two

3:58 wtf, im sure i did the problems in order, but now it seems like i skipped a bunch. have they been reordered>

3:58 ?

3:58 amalloy: matthias__: kinda-sorta. we were mis-sorting earlier, for a while

3:58 matthias__: ah, ok

3:59 damn, its also unsolved. good thing i have my solution copied D:

4:00 amalloy: matthias__: you don't have an account named matias, do you?

4:00 we have users named matthias and matias

4:02 matthias_: i'm matthias

4:02 why?

4:02 clojurebot: why not?

4:03 amalloy: i mean, if you accidentally signed in as matias as well as matthias, that would explain why you see as unsolved some problems you thought you solved

4:04 matthias_: yeah, i think its just because i solved the problem while not logged in. but i was pretty sure i logged in then and saw that it was marked as solved.

4:06 i think maybe the site should have good example solutions you see after you solve a problem so you can see what proper code would have looked like ;)

4:07 mids: and automatically classify users based on their kind of submissions; 'macro lover', 'java renegate', 'ruby monkeypatcher'

4:07 amalloy: mids: we welcome suggestions that won't result in users hating us :)

4:08 mids: darn :)

4:08 sweet site though, /me signs up

4:15 matthias_: (doc nil)

4:15 clojurebot: java.lang.NullPointerException

4:29 matthias_: i sometimes switch from a list to a vector just to change the order of the result. kinda feels like im doin it wrong

4:32 amalloy: matthias_: that's basically why both exist

4:32 matthias_: heh

4:34 almost all my solution are basically like: make a function, make a new function in it with an extra parameter, put and if in there and recur, call the inner function

9:57 kzar: Is there something like reduce that you can use when you've got a list of functions instead of just one?

9:58 shachaf: kzar: What do you mean?

10:01 kzar: shachaf: Well somthing like (reduce [#(+ 5 %) #(+ 3 %)] 0) that returns 8

10:01 shachaf: Oh. Just apply the list of functions in turn?

10:02 matthias_: you could turn those into one function

10:02 shachaf: Reduce the list with composition and id, I guess.

10:02 kzar: Yea it was a dumb example sorry

10:02 shachaf: Or with application and x.

10:03 opqdonut_: it's kinda dumb that #(%1 %2) doesn't have a name

10:04 or wait, is it (partial partial) or something like that?

10:04 kzar: I'm just hacking about trying to write a function that replaces characters in a string, I've got a list of functions (map (fn [a b] #(.replace % a b)) (seq "_-") (seq "/+")) and now I'm trying to figure out how to reduce the string with them

10:05 Chousuke: kzar: those seq calls are redundant, but hm

10:05 apply comp?

10:06 kzar: oh yea!

10:06 Chousuke: ,((apply comp [(partial + 5) -]) 10)

10:06 clojurebot: -5

10:09 kzar: Sweet it actually works, thanks :D

11:17 ev4l: mornin` everyone

11:17 anyone knows if there's a problem with mapping a side effecty fn over a seq inside a loop?

11:17 https://gist.github.com/939616

11:20 TimMc: ev4l: doall

11:21 ev4l: map returns a lazy seq -- so you need to force it

11:22 In short... (doall (map ...))

11:23 ev4l: TimMc: hmm nice! I haven't seen that form before =]

11:23 gotta remember about the lazyness

11:24 TimMc: Thanks alot. It worked!

11:25 TimMc: ev4l: Read up on doall, dorun, and doseq

11:25 ev4l: I think you actually want dorun here

11:25 ev4l: TimMc: Already doing it =D

11:28 TimMc: it seems that dorun is the one

11:28 TimMc: Yep, you don't care about the return value.

11:29 ev4l: TimMc: I actually don't care about the results, because all i do is to save each element of the seq in the DB

11:29 TimMc: :D

11:42 TimMc: thanks a bunch!

11:44 TimMc: np

11:44 ev4l: And now you know another debugging heuristic: If it looks like a side-effecty piece of your code isn't getting run when it should, look for lazy seqs.

11:49 ev4l: ev4l: Totally :) Initially i thought the problem was with the looping construct (it was the first time i actually used it.haha) , but after digging i came to the conclusion that it had something to do with using map+side-effecty fn

11:50 s/:\beval:/TimMc

11:54 robonobo: hi, is there a function that 'repeats' a seq into a new seq? so (repeat '(1 2 3) 3) => (1 2 3 1 2 3 1 2 3) ?

11:55 you could do it with for and flatten, but I know in python you can just multiply a list

11:57 opqdonut_: you can use cycle and take, too

11:58 robonobo: opqdonut_: nice, that's less verbose than the for-flatten thing

11:58 opqdonut_: IMO repeat + flatten is the best

11:59 ,(flatten (repeat 3 '(1 2 3)))

11:59 clojurebot: (1 2 3 1 2 3 1 2 3)

11:59 opqdonut_: but I guess there's no standard name for (comp flatten repeat)

12:00 :)

12:00 robonobo: thanks

12:01 wait, is cycle the same as repeat?

12:01 ah, no, i see

12:01 nvm

12:15 devn: java.lang.NoClassDefFoundError: com/mongodb/DB$WriteConcern (utils.clj:1)

12:15 woops

12:29 rien: seancorfield: cool, thanks!

12:29 technomancy: yes, I know you from #emacs :)

13:03 adamt: hi

13:05 i'm new with clojure and trying to get composure and com.ashafa.clutch working. https://gist.github.com/939700 is my project file and source. i used lein to install deps, but i'm getting the following error: java.io.FileNotFoundException: Could not locate com/ashafa/clutch__init.class or com/ashafa/clutch.clj on classpath: (core.clj:1)

13:06 Could anybody perhaps have a look and beat me with a bat while telling me what i did wrong? :)

14:38 ekoontz: so i'm getting runtime errors on my "lein ring" process:

14:38 http://pastebin.com/NuXDbey3

14:38 stack is impossible to debug :P

14:39 it happens randomly

14:39 not every time

15:05 * Licenser got his copy of "The Joy of Clojure" :D

16:07 thorwil: my view expects an IFn, but my model delivers a lazyseq

16:18 fliebel: thorwil: Oh, bad. What about #(seq the-lazy-seq) :) *joking*

16:18 thorwil: even with a cheat-sheet, i can't figure out how to bridge this

16:19 fliebel: thorwil: Depends on the context. What is in the lazy seq, and what kind of fn does the view need?

16:19 thorwil: and now i have to log off :/

16:19 fliebel: me too actually. :/

17:24 joshua__: $findfn (list 1 (list 1 2) 3) [1 [1 2] 3]

17:24 sexpbot: [clojure.set/union clojure.set/intersection clojure.set/difference clojure.core/list* clojure.core/distinct clojure.core/sequence clojure.core/vec clojure.core/concat clojure.core/seque clojure.core/seq clojure.core/doall clojure.core/macroexpand-1 clojure.core/comp ... http://gist.github.com/939892

17:54 joshua__: This is probably a silly question, but the documentation is confusing me. I understand a vector to have O(1) random access, but when I'm reading the docs it says that vectors in Clojure are functions of their indexes which use nth internally. When I read about nth it says that nth is O(n) for sequences.

17:54 So would that imply that vectors are O(n) access in Clojure!?!

17:57 *is reading blogs about vectors now, because that just doesn't sound right*

18:03 dnolen: ,(supers PersistentVector)

18:03 clojurebot: java.lang.Exception: Unable to resolve symbol: PersistentVector in this context

18:03 dnolen: ,(supers (class []))

18:03 clojurebot: #{clojure.lang.IObj clojure.lang.Sequential clojure.lang.Reversible clojure.lang.Counted java.lang.Comparable java.lang.Runnable clojure.lang.ILookup clojure.lang.Seqable clojure.lang.AFn clojure.lang.Indexed ...}

18:03 dnolen: (seq? [])

18:03 ,(seq? [])

18:03 clojurebot: false

18:03 dnolen: joshua__: ^

18:05 joshua__: Reading about vectors seems to imply that they are stored as a tree format with a branching factor of 32 which leads to a lookup factor of log_32(n). So now I'm thinking they have a log lookup time, which is better than the O(n) I was worried about before.

18:05 dnolen, thanks. I get the documentation now.

18:58 rosejn: is it really this empty in here?

19:22 joshua__: rosejn, It is a holiday atm.

19:22 rosejn: I figured most geeks were atheists :-)

19:24 joshua__: rosejn, I'm not. I'm still not looking forward to hunting eggs >.<

19:30 rosejn: joshua, haha, and that's the only fun part. You know the eggs are from the true origins of easter, older pagan religions...

19:33 joshua__: rosejn, I do.

19:37 rosejn, also the days of the week are named after pagan gods etc.

20:49 mreynolds: I'm building a protocol parser and I'm trying to do it more lazily than I'm currently doing it. The difficulty I'm running into is that the protocol has bits where I can read an entire "packet" because I know it's size, but also has variable length packets. I can think of a way to handle the known size packets (by reading off the entire thing into a buffer, then parsing the buffer when needed), but i'm not sure how to handle the

20:49 variable bits. Any suggestions or reading material I should look at?

20:50 gregh: does your variable part have a fixed size header? That's a common way to build a protocol. Then you can read the fixed size header and find out how much more to read

20:51 mreynolds: gregh: No, it's not a very well written protocol, and I can't change it :/

20:51 TimMc: joshua__: I celebrated Easter by feeding a Peep to a swan.

20:51 gregh: what determines the size of a variable length packet then?

20:52 mreynolds: gregh: it's something like this : int, int, string, short (short determines next packet, if short is -255, then terminate)

20:52 gregh: It's actually this : http://mc.kev009.com/Protocol

20:53 TimMc: haha

20:53 gregh: at first glance it looks like each variable length part is prefixed by a length

20:54 mreynolds: gregh: Search for "metadata"

20:54 0x28 doesn't have a length, at least the way I'm reading it

20:55 gregh: but http://mc.kev009.com/Protocol#Metadata describes the format of the metadata

20:57 mreynolds: gregh: Right, there's no size. Maybe I'm misunderstanding you? I can read the protocol. But right now I have to parse some packets completely, instead of just reading their length in and parsing it as needed. I'm trying to design something that, by default, just reads the bytes in for later parsing (true for most of the packets), but also can "degrade" to reading in the bytes and parsing them in a non-lazy fashion

20:58 gregh: yeah, it looks like you can't tell how big a metadata packet is without reading at least the structure

20:59 mreynolds: gregh: Yeah. Is there a known pattern for this style of parsing? I've been sort of beating my head against this problem for a bit without much success.

20:59 gregh: you could have a reader that just reads the bytes of a full packet, with knowledge of the internal structure

21:00 then have something else that takes a packet and extracts all the data items (ie. knows the *meaning* of the bytes)

21:00 mreynolds: gregh: Yeah, that's the path I went down, but got stuck when trying to do the optimized route of reading a full packet if none of the pieces are of unknown size

21:01 gregh: quit trying to optimize at this point :)

21:01 mreynolds: heh, yeah, agreed

21:01 I'll do the easy thing first

21:02 gregh: make it work first, because you can't get very far if it doesn't work

21:03 mreynolds: Yeah, I have the version based on a stream working first, but not as a sequence applying the operations against a stream. I'll do that first.

23:18 seancorfield__: amalloy_: hey! no fair! i'd got just one problem left to solve on 4clojure when i went out to dinner - when i came back you'd added another one!

23:18 done it tho'... just #53 to do...

23:49 amalloy: seancorfield__: hey, i'm in the same boat here. i go out for the day, and dbyrne keeps dragging me back with new problems i have to solve while on my android

23:50 dbyrne: amalloy, seancorfield: at least now we have an rss feed you can monitor so you know when new problems have been posted

23:55 seancorfield__: #53 is a tricky one...I don't think I've seen an elegant solution to it yet.

Logging service provided by n01se.net