title: Scheme Error, Return Binary Search Tree as Ordered List (R5RS)
body: <p>I am a noob at Scheme.  I have a binary search tree. The format of a node is a list of three elements, the first being the value at the node, the second being the left child node, and the third being the right child node. The "make" function creates an empty tree that looks like this: ( () () () ). I am able to create the tree, insert values, and find if a certain value exists in the tree.  My problem comes when I try to write a function that returns the tree as an ordered list.  Insert and Make functions:</p>
  
  <pre><code>;Inserts a number into the tree
  (define (insert t x)
      (cond ((null? (car t))
            (list x (make) (make)))
            ((&lt; x (car t))
             (list (car t) (insert (cadr t)  x) (caddr t)))
            ((&gt; x (car t))
             (list (car t) (cadr t) (insert (caddr t) x) ))
  
  
      )
  )
  
  ;Makes a new empty tree
  (define (make)
      (list (list) (list) (list))
   )
  </code></pre>
  
  <p>Those works fine.  Here is my as-list:</p>
  
  <pre><code>;Gives list of all numbers
  (define (as-list t)
      (cond
           (
             (null? (car t) )
             (list)
           )
            (
             #t
             (append (as-list (cadr t)) (as-list (car t)) (as-list (caddr t)))
           )
       )
    )
  </code></pre>
  
  <p>Running this, I get a contract violation, saying it expected "mpair?".  I do not believe this is a logic error on my part, but it may be.  Is this another parentheses problem?<br>
  Thank you for your time!</p>