title: Scheme Binary Search Tree Error (R5RS)
body: <p>I am completely new to Scheme and functional languages in general.  I am trying to create 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.  I have a "make" function, which creates an empty tree: ( () () () ).  I also have the insert function.  Here is the code:</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>To test it, I run the following lines:</p>
  
  <pre><code>&gt; (define b1 (make))
  &gt; (define b2 (insert b1 1))
  &gt; b2
  (1 (() () ()) (() () ()))
  &gt; (define b3 (insert b2 2))
  </code></pre>
  
  <p>I then receive the following error:</p>
  
  <pre><code>application: not a procedure;
  expected a procedure that can be applied to arguments
  given: (2 (() () ()) (() () ()))
  arguments...: [none]
  </code></pre>
  
  <p>I have checked and re-checked my parentheses...and running it in debug mode, I see it fails at the END of inserting 2 into the tree.  Until the, it works as planned.  Is this the cause of a foolish syntax/logic error on my part?</p>