title: Looking up pairing lists in scheme
body: <p>I am trying to write recursive scheme function that returns the binding (pair) whose name equals the given name. If no such binding is found return the null list.   An association list is a list of bindings of names to values: ((name1 val1) ... (namet valuet)). </p>
  
  <pre><code>(define (lookup name assoc_list) 
    (cond
      ((null? assoc_list) '())
      ((equal? name (car (car assoc_list))) car(assoc_list))
      (else (lookup name (cdr L)))))
  </code></pre>
  
  <p>I tested it out with</p>
  
  <pre><code>(define l1 '( (ben "short") (cara "walking") (dan "bald")))
  (lookup (car(car l1)) l1)
  </code></pre>
  
  <p>and  it failed
  but if i do</p>
  
  <pre><code>(define (look name assoc_list) 
    (cond
     ((null? assoc_list) #f)
     ((equal? name (car (car assoc_list))) #t)
     (else (lookup name (cdr L)))))
  </code></pre>
  
  <p>and run this in scheme</p>
  
  <pre><code>(define l1 '( (ben "short") (cara "walking") (dan "bald")))
  (lookup (car(car l1)) l1)
  </code></pre>
  
  <p>it returns #t</p>
  
  <p>why wont it return the car(assoc_list)
  next im going to write a recursive function (lookup-env name environment), which returns the binding with the specified name in an environment (i.e. list of association lists) and null if no such binding is found</p>
  
  <p>An environment can be represented by a list of association lists (i.e. a list of symbol tables), where the first element in the list is nearest scope, the second the next surrounding scope, and the last the outermost scope. </p>