title: Generating permutations lazily
body: <p>I'm looking for an algorithm to generate permutations of a set in such a way that I could make a lazy list of them in Clojure.  i.e. I'd like to iterate over a list of permutations where each permutation is not calculated until I request it, and all of the permutations don't have to be stored in memory at once.</p>
  
  <p>Alternatively I'm looking for an algorithm where given a certain set, it will return the "next" permutation of that set, in such a way that repeatedly calling the function on its own output will cycle through all permutations of the original set, in some order (what the order is doesn't matter).</p>
  
  <p>Is there such an algorithm?  Most of the permutation-generating algorithms I've seen tend to generate them all at once (usually recursively), which doesn't scale to very large sets.  An implementation in Clojure (or another functional language) would be helpful but I can figure it out from pseudocode.</p>