Re: My first Clojure program: request for code review

2011-01-05 Thread Benny Tsai
Hi Ken, Sorry for the very late response; I've been away for a friend's wedding. Though I'm not sure if I will end up using this macro frequently, it was highly educational to step through its inner workings. Thank you very much for putting it together. On Dec 23 2010, 11:07 pm, Ken Wesson wro

Re: My first Clojure program: request for code review

2010-12-29 Thread Marek Kubica
On Thu, 23 Dec 2010 21:06:49 -0800 (PST) Benny Tsai wrote: > Sure, that would be cool :) > > Sorry for the hijack, Marek! Oh, no problem. I learn from reading discussions :) regards, Marek -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post t

Re: My first Clojure program: request for code review

2010-12-23 Thread Ken Wesson
On Fri, Dec 24, 2010 at 12:06 AM, Benny Tsai wrote: >> You're welcome. Sorry I couldn't be of greater help. If you want, I >> could throw together a quickie macro for grabbing a few items from >> either end of a seq. > Sure, that would be cool :) OK, here goes ... (defmacro ends [[[firsts mid la

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
Sure, that would be cool :) Sorry for the hijack, Marek! On Dec 23, 5:09 pm, Ken Wesson wrote: > On Thu, Dec 23, 2010 at 7:08 PM, Benny Tsai wrote: > > On Dec 22, 11:42 am, Ken Wesson wrote: > >> I don't think Clojure has that. Closest is > > >> (let [[f & rst] [1 2 3 4 5] > >>       l (last r

Re: My first Clojure program: request for code review

2010-12-23 Thread Ken Wesson
On Thu, Dec 23, 2010 at 7:08 PM, Benny Tsai wrote: > On Dec 22, 11:42 am, Ken Wesson wrote: >> I don't think Clojure has that. Closest is >> >> (let [[f & rst] [1 2 3 4 5] >>       l (last rst) >>       m (butlast rst)] >>   [f m l]) >> >> Output is [1 (2 3 4) 5] >> >> Obviously, using the last e

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
On Dec 22, 11:42 am, Ken Wesson wrote: > I don't think Clojure has that. Closest is > > (let [[f & rst] [1 2 3 4 5] >       l (last rst) >       m (butlast rst)] >   [f m l]) > > Output is [1 (2 3 4) 5] > > Obviously, using the last element is non-lazy. It may well be that in > cases where you'd w

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
Neat trick! Thanks David :) On Dec 22, 11:23 am, David Nolen wrote: > On Wed, Dec 22, 2010 at 1:22 PM, David Nolen wrote: > > On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai wrote: > > >> Hi Ken, > > >> > user=> (let [[x y & more] [1 2 3 4 5]] [x y more]) > >> > [1 2 (3 4 5)] > >> > user=> (let [[

Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai wrote: > Hi Ken, > >> user=> (let [[x y & more] [1 2 3 4 5]] [x y more]) >> [1 2 (3 4 5)] >> user=> (let [[x y z] [1 2 3 4 5]] [x y z]) >> [1 2 3] >> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b]) >> [3 4] >> >> You can grab any fixed position in this way, a

Re: My first Clojure program: request for code review

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:22 PM, David Nolen wrote: > On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai wrote: > >> Hi Ken, >> >> > user=> (let [[x y & more] [1 2 3 4 5]] [x y more]) >> > [1 2 (3 4 5)] >> > user=> (let [[x y z] [1 2 3 4 5]] [x y z]) >> > [1 2 3] >> > user=> (let [[_ _ a b] [1 2 3 4 5]

Re: My first Clojure program: request for code review

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai wrote: > Hi Ken, > > > user=> (let [[x y & more] [1 2 3 4 5]] [x y more]) > > [1 2 (3 4 5)] > > user=> (let [[x y z] [1 2 3 4 5]] [x y z]) > > [1 2 3] > > user=> (let [[_ _ a b] [1 2 3 4 5]] [a b]) > > [3 4] > > > > You can grab any fixed position in th

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
> Just FYI, it's not applicable here but there is also rseq, which > returns a reversed view on a collection in constant time. It only > works on vectors and sorted maps, though. Good stuff, thank you Justin :) -- You received this message because you are subscribed to the Google Groups "Clojure

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Ken, > user=> (let [[x y & more] [1 2 3 4 5]] [x y more]) > [1 2 (3 4 5)] > user=> (let [[x y z] [1 2 3 4 5]] [x y z]) > [1 2 3] > user=> (let [[_ _ a b] [1 2 3 4 5]] [a b]) > [3 4] > > You can grab any fixed position in this way, as well as a "rest" that > is the tail of the sequence past the

Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 12:31 PM, Laurent PETIT wrote: > > > 2010/12/22 Ken Wesson >> >> On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai wrote: >> > Hi Marek, >> >> Great! I was wondering whether Clojure supports something like >> >> tuple-unpacking in Python. Does it also support "patterned" >> >>

Re: My first Clojure program: request for code review

2010-12-22 Thread Justin Kramer
On Dec 22, 10:59 am, Benny Tsai wrote: > > It does, but doesn't that make it less lazy? To reverse something, it > > needs to evaluate the whole sequence. I yet have to learn how to > > deal with lazyness. > You're right, I hadn't realized 'reverse' is not lazy (I have a lot to > learn about lazyn

Re: My first Clojure program: request for code review

2010-12-22 Thread Laurent PETIT
2010/12/22 Ken Wesson > On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai wrote: > > Hi Marek, > >> Great! I was wondering whether Clojure supports something like > >> tuple-unpacking in Python. Does it also support "patterned" > >> destructuring like: > >> > >> first, *middle, last = sequence(...) >

Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai wrote: > Hi Marek, >> Great! I was wondering whether Clojure supports something like >> tuple-unpacking in Python. Does it also support "patterned" >> destructuring like: >> >> first, *middle, last = sequence(...) >> -or- >> first, rest = sequence(...)

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Marek, > > - To sort the nicks by karma in descending order, instead of sorting > > by the negation of the karma, I used (reverse (sort-by ...)); again, > > just a subjective thing, makes the intent more clear to me. > > It does, but doesn't that make it less lazy? To reverse something, it > ne

Re: My first Clojure program: request for code review

2010-12-22 Thread Marek Kubica
Hi, Thanks for your review and your improvements (of course also to Justin, whose improvements are also useful). I'll try to merge them into some "optimal" solution :) On Tue, 21 Dec 2010 20:46:56 -0800 (PST) Benny Tsai wrote: > Hi Marek, > > Here's my tweaked version: > > (ns karma > (:use

Re: My first Clojure program: request for code review

2010-12-21 Thread Justin Kramer
Here's my version. Main points: * Use with-open & line-seq for worry-free laziness * Do everything in one swoop (reduce) * Perform one regexp match per line * Leverage ->> ;; (ns user (use [clojure.java.io :only [reader]])) (def re-vote #"([A-z]{1,16})(\+\+|\-\-)") (defn extract-votes [lin

Re: My first Clojure program: request for code review

2010-12-21 Thread Benny Tsai
Hi Marek, Here's my tweaked version: (ns karma (:use [clojure.contrib.duck-streams :only (read-lines)]) (:use [clojure.contrib.generic.functor :only (fmap)])) (def allowed-nickname "[A-z]{1,16}") (def upvote-regexp (re-pattern (format "(%s)\\+\\+" allowed- nickname))) (def downvote-regexp (r