Subject: Re: Basics of #'(lambda ...
From: Erik Naggum <erik@naggum.no>
Date: 19 Aug 2002 16:54:32 +0000
Newsgroups: comp.lang.lisp
Message-ID: <3238764872794264@naggum.no>

* Eli Bendersky
| However, if I try to omit the #' (which seems logical to me as mapcar really
| accepts a function, so to complicate it by dereferencing a symbol doesn't
| make much sense)

  #' is a reader macro just like '.  #'x means (function x) just as 'x means
  (quote x).  It is not as optional as you might think.  If you come from a
  Scheme background (which I believe you might do because you think that
  "logical" /alone/ is useful and has anything to do with language design,
  i.e., "alone" as apart from the /premises/ of the logic employed), you
  should realize that Common Lisp is not a dialect of Scheme and that you
  should endeavor to understand it in its own right.

  `lambda´ is a macro that returns the whole form wrapped in a `function´, so
  if you observe that it "works", the important thing is to understand /why/.

  So when you evaluate (lambda (x) (+ x 10)), the macro is first expanded so
  you get (function (lambda (x) (+ x 10))) which can then be evaluated to a
  function object and returned.

| Could you Lisp gurus please elaborate?  What is the right way to do it?

  The right way is to understand what the `function´ special operator does and
  then to use it consistently.  If you feel uncomfortable with the heavy use
  of punctuation marks in the #' reader macro, the easiest solution is to
  write "function" out in full.

  As you get more experienced with Common Lisp, you will see that `function´
  is also used to name functions that consist of more than a symbol name, so
  your initial assumption that it is the same as `symbol-function´ should be
  discarded as soon as possible.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.