Subject: Re: Another Newbie Question !!!
From: (Rob Warnock)
Date: Thu, 11 Dec 2008 22:26:59 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Thomas A. Russ <> wrote:
| Well, to really get reliable timings you need to insert
| (COMPILE 'FIND-FACTORS) into your script between the DEFUN
| and the TIME steps. Some lisps will automatically compile
| functions (IIRC CMUCL, SBCL and CCL do this) while others
| will use a separate (and slower) interpreter (LispWorks, ACL).

While that is true for SBCL, CMUCL still retains its interpreter,
which is used by default unless functions are explicitly compiled.

What sometimes confuses people is the fact that CMUCL automatically
"converts" or "minimally compiles" (CLHS functions the
first time they are called[1], and that this "conversion" includes
macro expansion, so that if a macro is redefined even interpreted
functions [if they've already been "converted"] have to be redefined
in order to pick up the new macro definition. So to this extent (only)
CMUCL's REPL behaves as if everything typed to the REPL is "compiled".

But in actual fact, even such "converted" functions still remain
truly interpreted unless/until explicitly compiled:

    cmu> (defmacro my-quote (form)
           (format *debug-io* "MY-QUOTE expanded to: ~s~%" form)

    cmu> (defun foo (x)
           (+ x (my-quote 52)))

    cmu> #'foo

    #<Interpreted Function FOO {489BE389}>
    cmu>  (foo 5)   ; First usage, function gets "converted".
    MY-QUOTE expanded to: 52

    cmu> (foo 10)   ; Notice that MY-QUOTE is *not* expanded again.

    cmu> #'foo      ; Yet FOO is still an interpreted function

    #<Interpreted Function FOO {489D02E1}>

Macros do get expanded one more time when a function is truly compiled:

    cmu> (compile 'foo)
    MY-QUOTE expanded to: 52
    ; Compiling LAMBDA (X): 
    ; Compiling Top-Level Form: 

    cmu> #'foo      ; Now a compiled function.

    #<Function FOO {489EC781}>
    cmu> (foo 17)   ; No further expansion.



[1] This noticeably helps the performance of "scripts" containing many
    functions of which only a few are called during any given execution.

Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607