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
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
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
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
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
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
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 [[
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
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]
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
> 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
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
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"
>> >>
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
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(...)
>
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(...)
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
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
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
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
20 matches
Mail list logo