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
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
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
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
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.
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
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
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
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
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
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
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
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:
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
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
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
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
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
18 matches
Mail list logo