title: Common Lisp Binary Tree
body: <p>I am trying to write a program in Common Lisp using GNU ClISP to compile it. I would like to enter a list such as <code>(A(B (C) ()) (D (E) (F (G) ())))</code> and depending on the first word print out the pre-, in-, or post-order traversal. Example: </p>
  
  <pre><code>(pre '(A(B (C)... etc))
  </code></pre>
  
  <p>I am having trouble putting my logic into Clisp notation. I currently have the following code:</p>
  
  <pre><code>(defun leftchild (L)(cadr L))
  
  (defun rightchild (L)(caddr L))
  
  (defun data (L)(car L))
  
  (defun pre (L)(if (null L) '()((data L)(pre(leftchild L))(pre(rightchild L)))))
  
  ... similar in and post functions
  </code></pre>
  
  <p>I get compiling errors saying that I should use a lambda in my pre function. I think this is due to the double (( infront of data because it is expecting a command, but I am not sure what I should put there. I don't think cond would work, because that would hinder the recursive loop. Also, will data L print as it is now? The compiler did not recognize <code>(print (data L))</code>. </p>
  
  <p>I have been working on this code for over a week now, trying to troubleshoot it myself, but I am at a loss. I would greatly appreciate it if someone could explain what I am doing incorrectly. </p>
  
  <p>Another question that I have is how can I make the program prompt a line to the user to enter the (pre '(A... etc)) so that when I run the compiled file the program will run instead of giving a funcall error?</p>
  
  <p>Thank you for your time. </p>