title: Using parameters as operators in LISP lambda function (The Roots of Lisp)
body: <p>I'm teaching myself lisp, mostly because I like the idea of being able to build programs from small axiomatic blocks. Learning lisp is a hobby project for me because i) it seems fun and ii) I want to see if it really does let me look at problems in a new way. To this end I'm working through Paul Graham's <em>The Roots of Lisp</em> article. I am using the SBCL implementation, though my issue occurs on other implementations also. I've encountered a problem trying to use parameters as operators in a lambda function:</p>
  <pre><code>((lambda (f) (f '(b c))) 
   '(lambda (x) (cons 'a x)))
  </code></pre>
  <p>Per section 2 of <em>The Roots of Lisp</em>, this should evaluate to <code>(a b c)</code>. This makes sense, the second lambda is a parameter to the first. Assuming my understanding is correct, the expression simplifies to:</p>
  <pre><code>((lambda (x) (cons 'a x)) '(b c))
  </code></pre>
  <p>Fine. Running the latter works as expected. However, running the former, unsimplified, expression results in the error: <code>The function COMMON-LISP-USER::F is undefined.</code> Other SO questions (<a href="https://stackoverflow.com/questions/8775687/higher-order-programming-with-lisp-passing-a-function-to-mapcar">here</a> and <a href="https://stackoverflow.com/questions/19054657/how-to-pass-arithmetic-operators-as-function-parameters-in-lisp">here</a>) lead me to believe this is something to do with the function vs variable namespaces in CL, and I've tried the <code>#'</code> syntax in various ways, but I can't seem to get it to work the way I'd expect. What should I do?</p>
  <p>Thanks!</p>