Re: filter on sequence

2009-06-02 Thread Vagif Verdi
On Jun 2, 7:55 am, Andrew Wagner 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 structure but also value

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 (a

Re: filter on sequence

2009-06-02 Thread Tassilo Horn
Wilson MacGyver 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 sense. It'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 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" idiomatic way of

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
The same is true of irrefutable patterns in haskell. > > The difference is that a pattern match can fail, and in that case > other patterns are tried. Clojure's destructuring assumes that the > value has the right structure. If it doesn't, then you will get an > exception thrown. > > --~--~-

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 destruct

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: http://groups.google.com/group/clojure/browse_frm/thread/0aa57ab265f7474a

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 subscri

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 6:02 PM, Michael Wood wrote: > On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner 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 differe

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner 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 it destructuring li

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 wrote: >> My first reaction was to do it using a sequence. Is this the clojur

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
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 wrote: >> You can use destructuring in your predicate's arg list: >> > >  Not to hijack the thread but...is there som

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 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 [[_ x]]

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:35 PM, Wilson MacGyver 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. > > what I li

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 subscr

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 > 46.166

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 sequentia

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 f