[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Son of Efficiency of Closures
Date: Fri, 20 Oct 89 10:54 EST
From: GODDEN@gmr.com
(defun return-a-closure (x)
#'(lambda (y)
(some-function x y)))
(compile 'return-a-closure)
(compiled-function-p (return-a-closure 'bar)) --> nil
Why isn't the returned closure a compiled function? This would indicate
that when the closure is later called, it is evaluated by the interpreter.
If that closure contained some really large Lisp form, then it's going to be
SLOW. Do I understand this correctly?
RETURN-A-CLOSURE doesn't return a compiled function, it returns a
lexical closure whose function is a compiled function.
(compiled-function-p (sys:lexical-closure-function (return-a-closure 'bar))) --> T
I think X3J13 may have voted the compiled-function data type out of the
standard. Examples like this indicate how difficult it is to make use
of it portably. There are other systems where the same data type is
used for compiled and interpreted functions; they effectively do
something like:
(defun make-interpreted-function (lambda-expression environment)
#'(lambda () (interpret-function lambda-expression environment)))
and the FUNCTION special form interpreter calls this when given a lambda
expression.
barmar