title: Tail-recursive Pascal triangle in Scheme
body: <p>I started to read <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%25_toc_start" rel="nofollow">SICP</a> recently, and I'm very interested in converting a recursive procedure into a tail-recursive form.</p>
  
  <p>For "one dimensional" situations (linear ones), like the Fibonacci series or factorial computation, it is not hard to do the conversion.</p>
  
  <p>For example, as the book says, we can rewrite the Fibonacci computation as follows</p>
  
  <pre><code>(define (fib n)
      (fib-iter 1 0 n))
  (define (fib-iter a b count)
      (if (= count 0) 
          b 
          (fib-iter (+ a b) a (- count 1))))
  </code></pre>
  
  <p>And this form is obviously <em>tail recursive</em></p>
  
  <p>However, for a "two dimensional" situation, like calculating Pascal's triangle (Ex 1.12 in SICP), we can still easily write a recursive solution like follows</p>
  
  <pre><code>(define (pascal x y) 
    (cond ((or (&lt;= x 0) (&lt;= y 0) (&lt; x y )) 0)
          ((or (= 1 y) (= x y) ) 1)
          (else (+ (pascal (- x 1) y) (pascal (- x 1) (- y 1))))))
  </code></pre>
  
  <p>The question is, how to convert this into a tail recursive form?</p>