title: Idiomatically avoiding recursion limit in scheme
body: <p>Note that I am using a custom implementation of scheme made for my school, so the functions may not look familiar, and your solutions may not work directly. I'm looking more for a generalized method.</p>
  
  <p>I have a recursive macro that evolves an L-system. Basically, it looks something like this:</p>
  
  <pre class="lang-lisp prettyprint-override"><code>(evolve lsys A A &lt; A &lt; B &gt; B &gt; A &lt; B &gt; B)
  ;; (lsys A A A A &lt; A A &lt; A &lt; B &gt; B &gt; A &lt; B &gt; B &gt; A A &lt; A &lt; B &gt; B &gt; A &lt; B &gt; B)
  </code></pre>
  
  <p>And so I've constructed a macro that essentially does this:</p>
  
  <pre class="lang-lisp prettyprint-override"><code>(evolve-n 3 lsys ...)
  ;; (evolve evolve evolve lsys ....)
  </code></pre>
  
  <p>Now the issue is, this list can get really very large very quickly. After just five evolutions I've exceeded the recursion limit. I could just increase the stack size, but not practically because I need to evolve this perhaps tens of times.</p>
  
  <p>The way that evolve works is takes a variadic number of arguments, the first of which is compared conditionally, and then appended to the result of calling evolve on the rest of the list. Something like this:</p>
  
  <pre class="lang-lisp prettyprint-override"><code>(define-macro (evolve (variadic ls))
      (if (eq? ls '())
          '()
          (let ((l (car ls)))
              (append 
                  (cond ((eq? l 'A) '(A A))
                        ((eq? l 'B) '(A &lt; B &gt; B))
                        (else (list l)))
                  (apply evolve (cdr ls))))))
  </code></pre>
  
  <p>So how can I unwrap this type of thing so it works iteratively rather than recursively?</p>