Re: Looping idiom

2009-09-10 Thread atreyu

uau cutting the Gordian knot

On 8 sep, 05:39, Timothy Pratley timothyprat...@gmail.com wrote:
 Yet another way :)

 user= (map + (rest a) a)
 (3 5 7 9 11)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Looping idiom

2009-09-08 Thread songoku

On Sep 8, 5:39 am, Timothy Pratley timothyprat...@gmail.com wrote:
 Yet another way :)

 user= (map + (rest a) a)
 (3 5 7 9 11)

wow! i like your solution!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Looping idiom

2009-09-08 Thread Sean Devlin

Very very slick :)

 On Sep 7, 11:39 pm, Timothy Pratley timothyprat...@gmail.com wrote:
  Yet another way :)
 
  user= (map + (rest a) a)
  (3 5 7 9 11)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Looping idiom

2009-09-07 Thread Brian Will

Very basic question. What's the idiom for producing a new seq wherein
each val is based on pairs from an existing seq, e.g.:

; add together n0 n1, n1 n2, n2 n3, etc.
[1 2 3 4 5 6]
; giving...
[3 5 7 9 11]

The verbose way would be something like:

(loop [s origSeq n [ ])
(let [a (first origSeq)
   b (second origSeq)]
(if (nil? b)
n
   (recur (rest origSeq) (conj n (+ a b))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Looping idiom

2009-09-07 Thread Brian Will

should read:

(loop [s origSeq n [ ])
(let [a (first s
   b (second s)]
(if (nil? b)
n
   (recur (rest s) (conj n (+ a b))

On Sep 7, 6:51 pm, Brian Will brian.thomas.w...@gmail.com wrote:
 Very basic question. What's the idiom for producing a new seq wherein
 each val is based on pairs from an existing seq, e.g.:

 ; add together n0 n1, n1 n2, n2 n3, etc.
 [1 2 3 4 5 6]
 ; giving...
 [3 5 7 9 11]

 The verbose way would be something like:

 (loop [s origSeq n [ ])
         (let [a (first origSeq)
                b (second origSeq)]
             (if (nil? b)
                 n
                (recur (rest origSeq) (conj n (+ a b))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Looping idiom

2009-09-07 Thread Sean Devlin

I'd use map, reduce, partial, and partition like so

user=(map (partial reduce +) (partition 2 1 [1 2 3 4 5 6]))
(3 5 7 9 11)

On Sep 7, 9:53 pm, Brian Will brian.thomas.w...@gmail.com wrote:
 should read:

 (loop [s origSeq n [ ])
         (let [a (first s
                b (second s)]
             (if (nil? b)
                 n
                (recur (rest s) (conj n (+ a b))

 On Sep 7, 6:51 pm, Brian Will brian.thomas.w...@gmail.com wrote:



  Very basic question. What's the idiom for producing a new seq wherein
  each val is based on pairs from an existing seq, e.g.:

  ; add together n0 n1, n1 n2, n2 n3, etc.
  [1 2 3 4 5 6]
  ; giving...
  [3 5 7 9 11]

  The verbose way would be something like:

  (loop [s origSeq n [ ])
          (let [a (first origSeq)
                 b (second origSeq)]
              (if (nil? b)
                  n
                 (recur (rest origSeq) (conj n (+ a b))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Looping idiom

2009-09-07 Thread Timothy Pratley

Yet another way :)

user= (map + (rest a) a)
(3 5 7 9 11)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---