+
+;;; support for the idiom (in MACROEXPAND and elsewhere) that NIL is
+;;; to be taken as a null lexical environment
+(defun coerce-to-lexenv (x)
+ (etypecase x
+ (null (make-null-lexenv))
+ (lexenv x)))
+
+;;; Is it safe to just grab the lambda expression LAMBDA in isolation,
+;;; ignoring the LEXENV?
+;;;
+;;; Note: The corresponding CMU CL code did something hairier so that
+;;; it could save inline definitions of DEFUNs in nontrivial lexical
+;;; environments. If it's ever important to try to do that, take a
+;;; look at the old CMU CL #'INLINE-SYNTACTIC-CLOSURE.
+(defun lambda-independent-of-lexenv-p (lambda lexenv)
+ (declare (type list lambda) (type lexenv lexenv))
+ (aver (eql (first lambda) 'lambda)) ; basic sanity check
+ ;; This is a trivial implementation that just makes sure that LEXENV
+ ;; doesn't have anything interesting in it. A more sophisticated
+ ;; implementation could skip things in LEXENV which aren't captured
+ ;; by LAMBDA, but this implementation doesn't try.
+ (and (null (lexenv-blocks lexenv))
+ (null (lexenv-tags lexenv))
+ (null (lexenv-vars lexenv))
+ (null (lexenv-funs lexenv))))