#clojure logs

2011-04-24

00:00KirinDaveThe 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.
00:01amalloyseancorfield__: go try it out. we luvs new users
00:01technomancyhuh; taking a peek
00:02technomancyKirinDave: heh; have you seen the Clojure peepcode?
00:02technomancyit's a lot like that.
00:02KirinDaveYes.
00:02KirinDaveActually
00:02KirinDaveThere are 3 ongoing projects
00:02KirinDaveIn this class
00:02KirinDaveI hope that this class could get this project to a state where multiple people could log in
00:03technomancyyeah, that's a simple way to get people thinking about consistency and concurrency
00:03KirinDaveIn this case, we're covering file i/o, basic data structures, and data driven programming.
00:05technomancysounds like fun
00:05technomancyI have a hard time gauging what kids can pull off, but provided the right level of hints I'm sure it would work.
00:05KirinDaveYeah
00:06KirinDaveI will just be in to help out every 2 weeks.
00:17brunoalfirevichelp /bar
00:17brunoalfirevicexit
00:53seancorfield__amalloy: i just did the first 40 4clojure problems :)
00:54amalloyseancorfield__: 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/
00:56seancorfield__the first one was so easy i got it wrong several times thinking it was asking something harder :)
00:56amalloyhaha
00:57seancorfield__then it was a pretty easy run for a while and then suddenly things seemed to get harder than they looked
00:57seancorfield__when i got to 41 my first few ideas at a solution were horribly complex
00:58amalloyseancorfield__: yeah, i was really thrown by how hard some of them wound up being
00:59amalloyi 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
01:00amalloyoh no, 44 was the hard one
01:00seancorfield__so i stopped to take a break... i'm sure i can figure out a simpler solution soon :)
02:43joshua__Whats the Clojure equivalent of writing a nested list comprehension?
02:43amalloyjoshua__: for supports nesting
02:43amalloy&(for [x (range 5) y (range x)] [x y])
02:43sexpbot⟹ ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3])
02:44joshua__amalloy, Nice. Thanks.
02:44amalloynote also the :when, :while, and :let keywords in (for...)
03:03joshua__amalloy, thanks amalloy, got it working =) https://gist.github.com/939383
03:08joshua__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
03:09amalloyit's pretty massive
03:09amalloynot quite as featured as CL's loop, but it doesn't have to be in a functional language
03:09joshua__I find it a little funny that I've never had to use it before now.. =p
03:11amalloyyeah you have. you've just used something else instead
03:13amalloyeg, ##(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]))
03:13sexpbot (into {} (map (fn [[k v]] [v k]) {1 2, 3... ⟹ {2 1, 4 3, 6 5}
03:13sexpbot (into {} (for [[k v] {1 2, 3 4, 5 6}] [v... ⟹ {2 1, 4 3, 6 5}
03:18amalloyjoshua__: ^
03:21joshua__amalloy, Thats what I meant, I think. I've been able to use other things to ape the functionality with some ease.
03:52amalloyjoshua__: ##(class #{1 2 3})
03:52sexpbot⟹ clojure.lang.PersistentHashSet
03:55matthias__amalloy, were you the guy who made 4clojure.com?
03:55amalloymatthias__: i was the second person to join the 4clojure team
03:55matthias__ah
03:55amalloycredit for the idea and the first draft goes to dbyrne
03:56matthias__i just finished one of the problems and it seems to have disappeared D:
03:56matthias__it was the one were interpose was forbidden. or was it interspose?
03:57matthias__also, one of the ones i had already solved is now unsolved (the reverse one). although i might have messed up the loging in
03:57amalloymatthias__: the problem disappeared, or your solution?
03:57matthias__the problem. i cant see it in the list anymore
03:57amalloymatthias__: try typing "inter" into the search bar at the top
03:57matthias__oh
03:57matthias__its on page two
03:58matthias__wtf, im sure i did the problems in order, but now it seems like i skipped a bunch. have they been reordered>
03:58matthias__?
03:58amalloymatthias__: kinda-sorta. we were mis-sorting earlier, for a while
03:58matthias__ah, ok
03:59matthias__damn, its also unsolved. good thing i have my solution copied D:
04:00amalloymatthias__: you don't have an account named matias, do you?
04:00amalloywe have users named matthias and matias
04:02matthias_i'm matthias
04:02matthias_why?
04:02clojurebotwhy not?
04:03amalloyi 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
04:04matthias_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.
04:06matthias_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 ;)
04:07midsand automatically classify users based on their kind of submissions; 'macro lover', 'java renegate', 'ruby monkeypatcher'
04:07amalloymids: we welcome suggestions that won't result in users hating us :)
04:08midsdarn :)
04:08midssweet site though, /me signs up
04:15matthias_(doc nil)
04:15clojurebotjava.lang.NullPointerException
04:29matthias_i sometimes switch from a list to a vector just to change the order of the result. kinda feels like im doin it wrong
04:32amalloymatthias_: that's basically why both exist
04:32matthias_heh
04:34matthias_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
09:57kzarIs there something like reduce that you can use when you've got a list of functions instead of just one?
09:58shachafkzar: What do you mean?
10:01kzarshachaf: Well somthing like (reduce [#(+ 5 %) #(+ 3 %)] 0) that returns 8
10:01shachafOh. Just apply the list of functions in turn?
10:02matthias_you could turn those into one function
10:02shachafReduce the list with composition and id, I guess.
10:02kzarYea it was a dumb example sorry
10:02shachafOr with application and x.
10:03opqdonut_it's kinda dumb that #(%1 %2) doesn't have a name
10:04opqdonut_or wait, is it (partial partial) or something like that?
10:04kzarI'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:05Chousukekzar: those seq calls are redundant, but hm
10:05Chousukeapply comp?
10:06kzaroh yea!
10:06Chousuke,((apply comp [(partial + 5) -]) 10)
10:06clojurebot-5
10:09kzarSweet it actually works, thanks :D
11:17ev4lmornin` everyone
11:17ev4lanyone knows if there's a problem with mapping a side effecty fn over a seq inside a loop?
11:17ev4lhttps://gist.github.com/939616
11:20TimMcev4l: doall
11:21TimMcev4l: map returns a lazy seq -- so you need to force it
11:22TimMcIn short... (doall (map ...))
11:23ev4lTimMc: hmm nice! I haven't seen that form before =]
11:23ev4lgotta remember about the lazyness
11:24ev4lTimMc: Thanks alot. It worked!
11:25TimMcev4l: Read up on doall, dorun, and doseq
11:25TimMcev4l: I think you actually want dorun here
11:25ev4lTimMc: Already doing it =D
11:28ev4lTimMc: it seems that dorun is the one
11:28TimMcYep, you don't care about the return value.
11:29ev4lTimMc: I actually don't care about the results, because all i do is to save each element of the seq in the DB
11:29ev4lTimMc: :D
11:42ev4lTimMc: thanks a bunch!
11:44TimMcnp
11:44TimMcev4l: 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:49ev4lev4l: 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:50ev4ls/:\beval:/TimMc
11:54robonobohi, 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:55robonoboyou could do it with for and flatten, but I know in python you can just multiply a list
11:57opqdonut_you can use cycle and take, too
11:58robonoboopqdonut_: nice, that's less verbose than the for-flatten thing
11:58opqdonut_IMO repeat + flatten is the best
11:59opqdonut_,(flatten (repeat 3 '(1 2 3)))
11:59clojurebot(1 2 3 1 2 3 1 2 3)
11:59opqdonut_but I guess there's no standard name for (comp flatten repeat)
12:00opqdonut_:)
12:00robonobothanks
12:01robonobowait, is cycle the same as repeat?
12:01robonoboah, no, i see
12:01robonobonvm
12:15devnjava.lang.NoClassDefFoundError: com/mongodb/DB$WriteConcern (utils.clj:1)
12:15devnwoops
12:29rienseancorfield: cool, thanks!
12:29rientechnomancy: yes, I know you from #emacs :)
13:03adamthi
13:05adamti'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:06adamtCould anybody perhaps have a look and beat me with a bat while telling me what i did wrong? :)
14:38ekoontzso i'm getting runtime errors on my "lein ring" process:
14:38ekoontzhttp://pastebin.com/NuXDbey3
14:38ekoontzstack is impossible to debug :P
14:39ekoontzit happens randomly
14:39ekoontznot every time
16:07thorwilmy view expects an IFn, but my model delivers a lazyseq
16:18fliebelthorwil: Oh, bad. What about #(seq the-lazy-seq) :) *joking*
16:18thorwileven with a cheat-sheet, i can't figure out how to bridge this
16:19fliebelthorwil: Depends on the context. What is in the lazy seq, and what kind of fn does the view need?
16:19thorwiland now i have to log off :/
16:19fliebelme too actually. :/
17:24joshua__$findfn (list 1 (list 1 2) 3) [1 [1 2] 3]
17:24sexpbot[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:54joshua__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:54joshua__So would that imply that vectors are O(n) access in Clojure!?!
17:57joshua__*is reading blogs about vectors now, because that just doesn't sound right*
18:03dnolen,(supers PersistentVector)
18:03clojurebotjava.lang.Exception: Unable to resolve symbol: PersistentVector in this context
18:03dnolen,(supers (class []))
18:03clojurebot#{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:03dnolen(seq? [])
18:03dnolen,(seq? [])
18:03clojurebotfalse
18:03dnolenjoshua__: ^
18:05joshua__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:05joshua__dnolen, thanks. I get the documentation now.
18:58rosejnis it really this empty in here?
19:22joshua__rosejn, It is a holiday atm.
19:22rosejnI figured most geeks were atheists :-)
19:24joshua__rosejn, I'm not. I'm still not looking forward to hunting eggs >.<
19:30rosejnjoshua, haha, and that's the only fun part. You know the eggs are from the true origins of easter, older pagan religions...
19:33joshua__rosejn, I do.
19:37joshua__rosejn, also the days of the week are named after pagan gods etc.
20:49mreynoldsI'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:49mreynoldsvariable bits. Any suggestions or reading material I should look at?
20:50greghdoes 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:51mreynoldsgregh: No, it's not a very well written protocol, and I can't change it :/
20:51TimMcjoshua__: I celebrated Easter by feeding a Peep to a swan.
20:51greghwhat determines the size of a variable length packet then?
20:52mreynoldsgregh: it's something like this : int, int, string, short (short determines next packet, if short is -255, then terminate)
20:52mreynoldsgregh: It's actually this : http://mc.kev009.com/Protocol
20:53TimMchaha
20:53greghat first glance it looks like each variable length part is prefixed by a length
20:54mreynoldsgregh: Search for "metadata"
20:54mreynolds0x28 doesn't have a length, at least the way I'm reading it
20:55greghbut http://mc.kev009.com/Protocol#Metadata describes the format of the metadata
20:57mreynoldsgregh: 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:58greghyeah, it looks like you can't tell how big a metadata packet is without reading at least the structure
20:59mreynoldsgregh: 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:59greghyou could have a reader that just reads the bytes of a full packet, with knowledge of the internal structure
21:00greghthen have something else that takes a packet and extracts all the data items (ie. knows the *meaning* of the bytes)
21:00mreynoldsgregh: 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:01greghquit trying to optimize at this point :)
21:01mreynoldsheh, yeah, agreed
21:01mreynoldsI'll do the easy thing first
21:02greghmake it work first, because you can't get very far if it doesn't work
21:03mreynoldsYeah, 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:18seancorfield__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:18seancorfield__done it tho'... just #53 to do...
23:49amalloyseancorfield__: 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:50dbyrneamalloy, seancorfield: at least now we have an rss feed you can monitor so you know when new problems have been posted
23:55dbyrneseancorfield__: #53 is a tricky one...I don't think I've seen an elegant solution to it yet.