title: Stackless Python - Recursion in a for loop?
body: <p>I'm fairly new to programming and I've been working with Python for a few months now. I'm trying to get a concept to work with Stackless, but just can't figure out how (though I've written <a href="http://pastebin.com/pn9cPcEf" rel="nofollow">other test scripts</a> that work with Stackless).</p>
  
  <p>Anywho, as a boiled down example consider the following code that runs through a list and finds all permutations (edit: n-dimensional cartesian products) of it by calling the same function recursively.</p>
  
  <pre><code>def traverseList(theList,temp,solutions,level=1):
      if level != len(theList):
          for x in theList:
              temp.append(x)
              traverseList(theList,temp,solutions,level+1)
              temp.pop()
      else:
          for x in theList:
              temp.append(x)
              solutions.append(temp[:])
              temp.pop()
  
  myList = ["a",None,2,"gamma",8] #the list doesn't always have just numbers
  solutionList = []
  tempList = []
  
  traverseList(myList,tempList,solutionList)
  print("%s... %s" %(solutionList[0], solutionList[-1]))
  </code></pre>
  
  <p>which yields:</p>
  
  <pre><code>['a', 'a', 'a', 'a', 'a']... [8, 8, 8, 8, 8]
  </code></pre>
  
  <p>So far it seems that the only examples I find with Stackless and recursion have the function sending information out at the end of the function after it's all done. Never in the middle of a for loop, as would be necessary in the above.</p>
  
  <p>How the heck would I do this? How would I turn this into a script that would run with tasklets rather than recursive functions? (<a href="http://pastebin.com/0RnvjVD3" rel="nofollow">This version</a> is the best I can come up with, but it fails no matter how I arrange it. This is one of many tries, I may as well throw spaghetti up against a wall at this point.)</p>
  
  <p>Bonus e-cookie for a way to do it without a bounceBack function - I haven't yet been able to find a way to have a single tasklet pass information to itself multiple times without one.</p>
  
  <p>Thanks for your time!</p>