user> (def a-blah (atom [1 2 3]))
#'user/a-blah
user> (defn blah [] (let [x (first @a-blah)] (swap! a-blah rest) x))
#'user/blah
user> (blah)
1
user> (blah)
2
user> (blah)
3
user> (blah)
nil
 
 
06.12.2013, 03:46, "David Simmons" <shortlypor...@gmail.com>:
Hi
 
I'd like to be able to define a function that is passed a vector of items and returns a function such that each time the returned function is called it returns the next item in my-vector.
 
For example 
 
(def blah (my-function [1 2 3])
 
(blah) => 1
(blah) => 2
(blah) => 3
 
Is this possible?
 
cheers
 
Dave
 

 

--
--
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/groups/opt_out.

--
--
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/groups/opt_out.

Reply via email to