On Sat, Jan 12, 2008 at 12:22:42PM -0800, SJS wrote:
Since lisp compiles incrementally, this can be a little unclear.
Um, that's not a /requirement/ for LISP, is it?
Yes, for anything that would be called Lisp. But, it's fairly loose as to
what "compile" means. A naive implementation could just leave the code in
SEXP form, and run that as part of evaluation.
Others will generate bytecode during compilation. Still others will
generate native assembly. Some do both, for example, when batch-compiling
a file, will generate native assembly, but will generate byte-code for
interactive use, or eval. Common Lisp defines a function
COMPILED-FUNCTION-P which returns true if the function is compiled instead
of interpreted. But, an implementation is allowed by compile as much as it
wants.
SBCL generates native code for all expression evaluated, even if you just
type them at the interactive prompt.
Emacs lisp compiles to byte code when asked to, otherwise interprets the
represented SEXPS of the program text.
LISP does make it easy to modify running code, right? Just not via the
macro system.
The macros system doesn't really have anything to do with modifying running
code, macros are just for manipulating the representation of the code.
But, in addition to eval, which evokes the parser and possibly compiler,
COMPILE is also available, which can replace the definition of an existing
piece of compiled code.
So yes, its quite easy to compile new code and run it. One thing that
makes it so easy is that the source representation is also a very natural
data representation in the language.
Having something like 'eval' allows you to get the same effect as could be
done with self-modifying code, but with a lot more safety, since the
compiler/interpreter is helping you. Macros won't help you modify the code
that is running.
Well, technically, you might make some macros that could help. . . :)
Yeah. Generally, you wouldn't want to write any lisp without using macros.
Loops using the iteration macros are much nicer than loops written with
gotos (which is the primitive).
Dave
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg