Subject: Re: Another Newbie Question !!!
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 11 Dec 2008 22:26:59 -0600
Newsgroups: comp.lang.lisp
Message-ID: <NqydnckEudqOddzUnZ2dnUVZ_vWdnZ2d@speakeasy.net>
Thomas A. Russ <tar@sevak.isi.edu> 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 3.2.2.2) 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)
           form)

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

    FOO
    cmu> #'foo

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

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

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

    #<Interpreted Function FOO {489D02E1}>
    cmu> 

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: 

    FOO
    NIL
    NIL
    cmu> #'foo      ; Now a compiled function.

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

    69
    cmu> 


-Rob

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

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607