Yeah, sorry Dimitri, I wasn't very clear :-) I meant that if you were going 
to do it recursively you would be using the first element of the seq, and 
you would be passing the (rest) of the seq to the subsequent recursive 
call. Very elegant solution!

On Thursday, 9 August 2012 12:29:12 UTC+1, Jim foo.bar wrote:
>
> On 09/08/12 12:00, David Powell wrote: 
> > You can try using the multi-input version of map to knit your data 
> > together with some other, potentially infinite, sequence: 
> > 
> >    (map vector items (cycle [black white])) 
> > 
> > It returns something like this: 
> > 
> >    ([item1 black] [item2 white] [item3 black] [item4 white]) 
> > 
> > Then you can use doseq over that, using destructuring to pick apart 
> > the items and colours and do something appropriate with each of them. 
> > 
>
> Thanks Dave that is pretty clever and looks very idiomatic! I managed to 
> get what I by using your suggestion: 
>
> (defn draw-grid2 [d g] 
>    (let [w (width d) 
>          h (height d) 
>          tiles (map vector (for [x (range 0 w 50) 
>                                  y (range 0 h 50)] [x y]) 
>                            (cycle [java.awt.Color/WHITE 
>                                    java.awt.Color/BLACK]))] 
>      (doseq [[[x y] c] tiles] 
>         (.setColor g c) 
>         (.fillRect g x y 50 50)) )) 
>
>
> Thanks a lot! It looked impossible to achieve without mutation, indices 
> and counting pixels!!! 
>
> Jim 
>

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

Reply via email to