2011-04-24
| 00: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. |
| 00:01 | amalloy | seancorfield__: go try it out. we luvs new users |
| 00:01 | technomancy | huh; taking a peek |
| 00:02 | technomancy | KirinDave: heh; have you seen the Clojure peepcode? |
| 00:02 | technomancy | it's a lot like that. |
| 00:02 | KirinDave | Yes. |
| 00:02 | KirinDave | Actually |
| 00:02 | KirinDave | There are 3 ongoing projects |
| 00:02 | KirinDave | In this class |
| 00:02 | KirinDave | I hope that this class could get this project to a state where multiple people could log in |
| 00:03 | technomancy | yeah, that's a simple way to get people thinking about consistency and concurrency |
| 00:03 | KirinDave | In this case, we're covering file i/o, basic data structures, and data driven programming. |
| 00:05 | technomancy | sounds like fun |
| 00:05 | technomancy | I have a hard time gauging what kids can pull off, but provided the right level of hints I'm sure it would work. |
| 00:05 | KirinDave | Yeah |
| 00:06 | KirinDave | I will just be in to help out every 2 weeks. |
| 00:17 | brunoalfirevic | help /bar |
| 00:17 | brunoalfirevic | exit |
| 00:53 | seancorfield__ | amalloy: i just did the first 40 4clojure problems :) |
| 00: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/ |
| 00:56 | seancorfield__ | the first one was so easy i got it wrong several times thinking it was asking something harder :) |
| 00:56 | amalloy | haha |
| 00:57 | seancorfield__ | then it was a pretty easy run for a while and then suddenly things seemed to get harder than they looked |
| 00:57 | seancorfield__ | when i got to 41 my first few ideas at a solution were horribly complex |
| 00:58 | amalloy | seancorfield__: yeah, i was really thrown by how hard some of them wound up being |
| 00:59 | amalloy | 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 |
| 01:00 | amalloy | oh no, 44 was the hard one |
| 01:00 | seancorfield__ | so i stopped to take a break... i'm sure i can figure out a simpler solution soon :) |
| 02:43 | joshua__ | Whats the Clojure equivalent of writing a nested list comprehension? |
| 02:43 | amalloy | joshua__: for supports nesting |
| 02:43 | amalloy | &(for [x (range 5) y (range x)] [x y]) |
| 02:43 | sexpbot | ⟹ ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3]) |
| 02:44 | joshua__ | amalloy, Nice. Thanks. |
| 02:44 | amalloy | note also the :when, :while, and :let keywords in (for...) |
| 03:03 | joshua__ | amalloy, thanks amalloy, got it working =) https://gist.github.com/939383 |
| 03:08 | joshua__ | 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:09 | amalloy | it's pretty massive |
| 03:09 | amalloy | not quite as featured as CL's loop, but it doesn't have to be in a functional language |
| 03:09 | joshua__ | I find it a little funny that I've never had to use it before now.. =p |
| 03:11 | amalloy | yeah you have. you've just used something else instead |
| 03:13 | amalloy | 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])) |
| 03:13 | sexpbot | (into {} (map (fn [[k v]] [v k]) {1 2, 3... ⟹ {2 1, 4 3, 6 5} |
| 03:13 | sexpbot | (into {} (for [[k v] {1 2, 3 4, 5 6}] [v... ⟹ {2 1, 4 3, 6 5} |
| 03:18 | amalloy | joshua__: ^ |
| 03:21 | joshua__ | amalloy, Thats what I meant, I think. I've been able to use other things to ape the functionality with some ease. |
| 03:52 | amalloy | joshua__: ##(class #{1 2 3}) |
| 03:52 | sexpbot | ⟹ clojure.lang.PersistentHashSet |
| 03:55 | matthias__ | amalloy, were you the guy who made 4clojure.com? |
| 03:55 | amalloy | matthias__: i was the second person to join the 4clojure team |
| 03:55 | matthias__ | ah |
| 03:55 | amalloy | credit for the idea and the first draft goes to dbyrne |
| 03:56 | matthias__ | i just finished one of the problems and it seems to have disappeared D: |
| 03:56 | matthias__ | it was the one were interpose was forbidden. or was it interspose? |
| 03:57 | matthias__ | 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:57 | amalloy | matthias__: the problem disappeared, or your solution? |
| 03:57 | matthias__ | the problem. i cant see it in the list anymore |
| 03:57 | amalloy | matthias__: try typing "inter" into the search bar at the top |
| 03:57 | matthias__ | oh |
| 03:57 | matthias__ | its on page two |
| 03:58 | matthias__ | wtf, im sure i did the problems in order, but now it seems like i skipped a bunch. have they been reordered> |
| 03:58 | matthias__ | ? |
| 03:58 | amalloy | matthias__: kinda-sorta. we were mis-sorting earlier, for a while |
| 03:58 | matthias__ | ah, ok |
| 03:59 | matthias__ | damn, its also unsolved. good thing i have my solution copied D: |
| 04:00 | amalloy | matthias__: you don't have an account named matias, do you? |
| 04:00 | amalloy | we have users named matthias and matias |
| 04:02 | matthias_ | i'm matthias |
| 04:02 | matthias_ | why? |
| 04:02 | clojurebot | why not? |
| 04: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 |
| 04: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. |
| 04:06 | matthias_ | 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:07 | mids | and automatically classify users based on their kind of submissions; 'macro lover', 'java renegate', 'ruby monkeypatcher' |
| 04:07 | amalloy | mids: we welcome suggestions that won't result in users hating us :) |
| 04:08 | mids | darn :) |
| 04:08 | mids | sweet site though, /me signs up |
| 04:15 | matthias_ | (doc nil) |
| 04:15 | clojurebot | java.lang.NullPointerException |
| 04: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 |
| 04:32 | amalloy | matthias_: that's basically why both exist |
| 04:32 | matthias_ | heh |
| 04:34 | matthias_ | 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:57 | kzar | Is there something like reduce that you can use when you've got a list of functions instead of just one? |
| 09: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 | opqdonut_ | 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 | Chousuke | 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 | ev4l | anyone knows if there's a problem with mapping a side effecty fn over a seq inside a loop? |
| 11:17 | ev4l | https://gist.github.com/939616 |
| 11:20 | TimMc | ev4l: doall |
| 11:21 | TimMc | ev4l: map returns a lazy seq -- so you need to force it |
| 11:22 | TimMc | In short... (doall (map ...)) |
| 11:23 | ev4l | TimMc: hmm nice! I haven't seen that form before =] |
| 11:23 | ev4l | gotta remember about the lazyness |
| 11:24 | ev4l | TimMc: Thanks alot. It worked! |
| 11:25 | TimMc | ev4l: Read up on doall, dorun, and doseq |
| 11:25 | TimMc | ev4l: I think you actually want dorun here |
| 11:25 | ev4l | TimMc: Already doing it =D |
| 11:28 | ev4l | 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 | ev4l | TimMc: :D |
| 11:42 | ev4l | TimMc: thanks a bunch! |
| 11:44 | TimMc | np |
| 11:44 | TimMc | 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 | ev4l | 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 | robonobo | 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 | opqdonut_ | ,(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 | opqdonut_ | :) |
| 12:00 | robonobo | thanks |
| 12:01 | robonobo | wait, is cycle the same as repeat? |
| 12:01 | robonobo | ah, no, i see |
| 12:01 | robonobo | nvm |
| 12:15 | devn | java.lang.NoClassDefFoundError: com/mongodb/DB$WriteConcern (utils.clj:1) |
| 12:15 | devn | woops |
| 12:29 | rien | seancorfield: cool, thanks! |
| 12:29 | rien | technomancy: yes, I know you from #emacs :) |
| 13:03 | adamt | hi |
| 13:05 | adamt | 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 | adamt | 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 | ekoontz | http://pastebin.com/NuXDbey3 |
| 14:38 | ekoontz | stack is impossible to debug :P |
| 14:39 | ekoontz | it happens randomly |
| 14:39 | ekoontz | not every time |
| 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 | joshua__ | So would that imply that vectors are O(n) access in Clojure!?! |
| 17:57 | joshua__ | *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 | dnolen | ,(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 | joshua__ | 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 | joshua__ | 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 | mreynolds | 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 | mreynolds | 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 | mreynolds | 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 | gregh | 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 | mreynolds | 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 | seancorfield__ | 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 | dbyrne | seancorfield__: #53 is a tricky one...I don't think I've seen an elegant solution to it yet. |