If you really want something that can be called repeatedly and returns something different each time (rather than just iterating through an infinite sequence, which seems like it would be the more functional-ish approach):
user> (defn cycle-gen [input] (let [iter (atom (cycle input))] (fn [] (let [v (first @iter)] (swap! iter rest) v)))) #'user/cycle-gen user> (def colors (cycle-gen '(red green blue))) #'user/colors user> (colors) red user> (colors) green user> (colors) blue user> (colors) red user> (colors) green user> (colors) blue On Wed, Mar 26, 2014 at 12:59 PM, Christopher Howard <cmhowa...@alaska.edu>wrote: > Hi. I'm still fairly new to Clojure. I was wondering: What's the > easiest way to make a generator (or something that would be as useful). > In one application, I need something that will return a different color > each time I call it - following a predefined list of colors, and > starting over again at the beginning when colors are exhausted. > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.