From: glauber
Subject: Compiled formatter function
Date: 
Message-ID: <892f97d1.0108070408.199bb2a3@posting.google.com>
I just came across an interesting case of Lisp "doing the right thing"
(or DWIMming as some say):

(formatter format-string) returns a function that can be used in place
of format, probably with better performance. For example:
(defvar xfmt (formatter "~a~%"))

Since formatter in interactive mode returns an interpreted function, i
thought that in order to get it compiled i would have to do something
like
(defvar xfmt-compiled (compile nil xfmt))

This works, but isn't necessary, because when i put 
(defvar xfmt (formatter "~a~%"))
in a file and compiled the file, the function stored in xfmt was
already, magically, compiled!

How does this work?

I'm using CLisp 2.26. The Hyperspec on formatter didn't say anything
about compilation. Is this the way formatter is handled in other
Common Lisps too?
From: Kent M Pitman
Subject: Re: Compiled formatter function
Date: 
Message-ID: <sfwvgjz9ayc.fsf@world.std.com>
··········@my-deja.com (glauber) writes:

> ... when i put 
> (defvar xfmt (formatter "~a~%"))
> in a file and compiled the file, the function stored in xfmt was
> already, magically, compiled!
> How does this work?

The same way as with any function.  FORMATTER probably expands to a
#'(LAMBDA ...)
which yields an interpreted function in interpreters and a compiled function
when executed compiled.

> 
> I'm using CLisp 2.26. The Hyperspec on formatter didn't say anything
> about compilation. Is this the way formatter is handled in other
> Common Lisps too?

It doesn't say anything about compilation in the case of

 (LET ((X #'(LAMBDA (X) (+ X 3))))
   (FUNCALL X 4))

but it does get compiled.  The whole language gets compiled when you use
a compiler.  ;-)