[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Top level forms in a compiled file

    Date: Thursday, 14 July 1983, 18:13-PDT
    From: BENSON at SPA-Nimbus

    ... This is handled in PSL by having function definitions add a call to FSET
    to the list of top level forms to be compiled.  It is exactly as if ...

    (defmacro defun (name &body body)
      `(setf (symbol-function ',name) #',(lambda ,@body)))

    Even defining a function twice in a single file and using both
    definitions works...

I assume you meant #'(lambda ,@body) rather than #',(lambda ,@body).
In any case, now that you mention it, I once wrote a simple Lisp compiler
which used this same trick. This style of presentation is also satisfactory
to me. It is maximally parallel with scheme, where 
 (setf (symbol-function ',name) #'(lambda ,@body))
would "macroexpand" to
 (setq ,name (lambda ,@body))

In fact, it's probably a loss to have the primitive conceptual unit not be 
#'(lambda ...), since anything else is almost sure to eventually turn up 
deficient for some extension to def- syntax.

So I'd support this as a semantic model. Actually, named-lambda might be better
than lambda, but that's no big deal.

What follows is just speculation; not in any way a proposal. It's interesting 
to note that if
 FILE1 = [ (defun f (x) x) (defun g (x) x) ]
"means" roughly...
 (defun g0001 (x) x)
 (defun g0002 (x) x)
 (defun g0003 () (setf #'f #'g0001) (setf #'g #'g0002))
then (load "FILE1") is the same as (G0003) so we could in principle have a
function PRELOAD which was like LOAD but just "got everything in core" without
doing any major side-effects. Then (LOAD "FILE1") might just do (G0003) without
having to move bits from disk to core. Also, there might be a function RELOAD
which just re-ran G0003 rather than moving a second set of the code into core.
It wouldn't fix bashed constants, but that might either be know to be desirable
or at least harmless for some applications.