filter on sequence

2009-06-02 Thread Wilson MacGyver
Apologies in advance on a very newbie question. I've constructed a sequence (take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2 (Math/log 2))]) doing a take 10 on it, produce the pairs I expect. what I like to know is, how do I filter for with value b is X for example, the

Re: filter on sequence

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote: what I like to know is, how do I filter for with value b is X You can use destructuring in your predicate's arg list: (filter (fn [[_ x]] ( x 10)) *1) In English, the function takes an argument which can be accessed

Re: filter on sequence

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 17:35, Wilson MacGyver wrote: for example, the first 10 produces. ([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268] [16 3.8471867757039027] [32 5.7707801635558535] [64 9.233248261689365] [128 15.38874710281561] [256 26.380709319112476] [512

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
You can use destructuring in your predicate's arg list: Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? --~--~-~--~~~---~--~~ You received this message because you are

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:35 PM, Wilson MacGyver wmacgy...@gmail.com wrote: Apologies in advance on a very newbie question. I've constructed a sequence (take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2 (Math/log 2))]) doing a take 10 on it, produce the pairs I expect.

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
ah, got it. thanks! On Tue, Jun 2, 2009 at 11:48 AM, Stephen C. Gilardi squee...@mac.com wrote: On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote: what I like to know is, how do I filter for with value b is X You can use destructuring in your predicate's arg list:        (filter (fn

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
actually I had the exact same reaction. So I'd echo Andrew's comment. Is this different than pattern-matching in say haskell/scala? On Tue, Jun 2, 2009 at 11:55 AM, Andrew Wagner wagner.and...@gmail.com wrote: You can use destructuring in your predicate's arg list:  Not to hijack the thread

Re: filter on sequence

2009-06-02 Thread Stuart Halloway
Ditto what everyone else said, plus let's get rid of the duplicated call to Math/log by splitting the iterate into an iterate + a map: (take-while (fn [[_ second]] ( second 10)) (map (fn [x] [x (/ x (Math/log x))]) (iterate #(* % 2) 2))) Stu On 02.06.2009, at 17:35, Wilson

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
I saw that clojure has loop. But in other functional languages, using loops are always discouraged. So I didn't know if loop was the clojure idiomatic way of doing this. On Tue, Jun 2, 2009 at 11:52 AM, Konrad Hinsen konrad.hin...@laposte.net wrote: My first reaction was to do it using a

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wagner.and...@gmail.com wrote: You can use destructuring in your predicate's arg list:  Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? Why doesn't Ruby just call

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 6:02 PM, Michael Wood esiot...@gmail.com wrote: On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wagner.and...@gmail.com wrote: You can use destructuring in your predicate's arg list:  Not to hijack the thread but...is there some reason clojure doesn't just just call this

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
Why doesn't Ruby just call it destructuring like Lisp has been doing for decades? ;) So that non-academics have a prayer at not getting scared away by an unnecessarily-technical name? --~--~-~--~~~---~--~~ You received this message because you are subscribed

Re: filter on sequence

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 11:55 AM, Andrew Wagner wrote: Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? This thread has some info on that:

Re: filter on sequence

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 18:00, Wilson MacGyver wrote: actually I had the exact same reaction. So I'd echo Andrew's comment. Is this different than pattern-matching in say haskell/scala? The difference is that a pattern match can fail, and in that case other patterns are tried. Clojure's

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
I see. very clever. I'm not used to loop constructs with no side effect. On Tue, Jun 2, 2009 at 12:21 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: I saw that clojure has loop. But in other functional languages, using loops are always discouraged. So I didn't know if loop was the clojure

Re: filter on sequence

2009-06-02 Thread Tassilo Horn
Wilson MacGyver wmacgy...@gmail.com writes: Hi Wilson, I saw that clojure has loop. But in other functional languages, using loops are always discouraged. So I didn't know if loop was the clojure idiomatic way of doing this. Clojure's `loop' (with `recur') is no real loop in an imperative

Re: filter on sequence

2009-06-02 Thread Richard Newman
Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? I guess the simplest answer is because it's destructuring, not pattern-matching :) As Rich explained in the thread to which Stephen linked, pattern matching (at

Re: filter on sequence

2009-06-02 Thread Vagif Verdi
On Jun 2, 7:55 am, Andrew Wagner wagner.and...@gmail.com wrote: You can use destructuring in your predicate's arg list:  Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? Pattern matching matches not only