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

Re: Quick question about lexically scoped defun...



    Date: Fri, 8 Jul 88 13:36 EDT
    From: David L. Andre <DLA@JASPER.SCRC.Symbolics.COM>

        Date: Thu, 7 Jul 88 20:43 PDT
        From: Siskind.pa@Xerox.COM

            All the complexity in that function is to be able to ask an intelligent
            question.  If you don't want the question asked, replace it with:

            (DEFUN ENCLOSE-TOP-LEVEL (LAMBDA ENV NAME)
              ENV)

            I agree that there should be a parameter to control this.

        I had a function that was defined in a non null lexical environment.
        I first compiled it and got the apropriate warning to which I
        answered Yes. I then made the above change to ENCLOSE-TOP-LEVEL
        and recompiled the function. I got this compiler warning:

        Compiling DEFINE-CLAUSE-SET SIMPLE-EXAMPLE
        For Function SIMPLE-EXAMPLE-2
          Function SIMPLE-EXAMPLE-2 is being redefined with an unsafeguarded definition.
          Its previous definition was safeguarded.

        What does this mean? Will non-null lexical environments work now?

    I cannot reproduce this.  However, you can safely ignore the warning.
    Please send me a complete example which generates the warning.

Here is a scenario which you can try:

Command: (let ((x 0)) (defun bar () x))
You have attempted to define BAR in a non-null lexical environment using a form usually used at top level.  It
references freely the variable X, which is bound by the lexical environment.
Do you want the definition to use the lexical environment? (Yes or No) Yes
BAR
Command: (bar)
0
Command: (defun si:enclose-top-level (lambda env name) env)
Warning:  Function SI:ENCLOSE-TOP-LEVEL, being redefined,
was previously defined by file BD:>rel-7>sys>eval. OK? (Y, P, or N) Yes.
SI:ENCLOSE-TOP-LEVEL
Command: (bar)
0
Command: (defun bar () 1)
BAR
Command: (bar)
Trap: The function NIL is undefined.

EVAL
   Arg 0 (SYS:FORM): (BAR)
   Arg 1 (SI:ENV): NIL
s-A, :    Supply a value to use this time as the definition of NIL
s-B, s-sh-C:   Supply a value to store permanently as the definition of NIL
s-C:           Retry the FSYMEVAL instruction
s-D, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-E:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

Command: (let ((x 2)) (defun bar () x))
BAR
Command: (bar)
Error: The object (NIL #<DTP-LOCATIVE 101234444> #<DTP-LOCATIVE 101234445>) is not a valid function

SI:DIGEST-LAMBDA
   Arg 0 (FUNCTION): (NIL #<DTP-LOCATIVE 101234444> #<DTP-LOCATIVE 101234445>)
   Arg 1 (SI:ENV): NIL
   Arg 2 (SI:NAME): NIL
   Arg 3 (SI:INTERNAL): NIL
s-A, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-B:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

Command: (defun bar () 3)
For Function BAR
  Function BAR is being redefined with an unsafeguarded definition.
  Its previous definition was safeguarded.
BAR
Command: (bar)
Trap: The function NIL is undefined.

EVAL
   Arg 0 (SYS:FORM): (BAR)
   Arg 1 (SI:ENV): NIL
s-A, :    Supply a value to use this time as the definition of NIL
s-B, s-sh-C:   Supply a value to store permanently as the definition of NIL
s-C:           Retry the FSYMEVAL instruction
s-D, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-E:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

Command: (let ((x 4)) (defun bar () x))
BAR
Command: (bar)
Error: The object (NIL #<DTP-LOCATIVE 101234444> #<DTP-LOCATIVE 101234445>) is not a valid function

SI:DIGEST-LAMBDA
   Arg 0 (FUNCTION): (NIL #<DTP-LOCATIVE 101234444> #<DTP-LOCATIVE 101234445>)
   Arg 1 (SI:ENV): NIL
   Arg 2 (SI:NAME): NIL
   Arg 3 (SI:INTERNAL): NIL
s-A, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-B:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

As you can see, once I redefine SI:ENCLOSE-TOP-LEVEL, *no* DEFUNs work anymore
whether or not they have lexical environments. I only get a warning however
when, I *first* compile a function, say BAR with a non-null lexical environment,
and *then* recompile the same function again, this time without a non-null
lexical environment.

  (defun baz () 1)
BAZ
  #'baz 
NIL
  (defun baz () 1)
BAZ
  (defun baz () 1)
BAZ
  (baz)
Trap: The function NIL is undefined.

EVAL
   Arg 0 (SYS:FORM): (BAZ)
   Arg 1 (SI:ENV): NIL
s-A, :    Supply a value to use this time as the definition of NIL
s-B, s-sh-C:   Supply a value to store permanently as the definition of NIL
s-C:           Retry the FSYMEVAL instruction
s-D, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-E:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

  (compile 'baz)
Error: Cannot find LAMBDA expression for BAZ

COMPILE
   Arg 0 (SYS:FUNCTION-SPEC): BAZ
   --Defaulted args:--
   Arg 1 (COMPILER:LAMBDA-EXP): NIL
s-A, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-B:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

  (let ((x 0)) (defun baz () x))
BAZ
  #'baz 
(#<DTP-LOCATIVE 101234441>)
  (compile 'baz)
Error: Don't know how to copy #<DTP-LOCATIVE 100370124> out of STACK-AREA

SYS:COPY-IF-NECESSARY
   Arg 0 (SI:THING): #<DTP-LOCATIVE 100370124>
   Arg 1: 4
s-A, :
s-B:           Restart process Dynamic Lisp Listener 1
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

  (let ((x 0)) (defun baz () x))
For Function BAZ
  Function BAZ is being redefined with an unsafeguarded definition.
  Its previous definition was safeguarded.
BAZ
  (let ((x 0)) (defun baz () x))
For Function BAZ
  Function BAZ is being redefined with an unsafeguarded definition.
  Its previous definition was safeguarded.
BAZ
  #'baz 
(#<DTP-LOCATIVE 101234441>)
  (compile 'baz)
Error: Don't know how to copy #<DTP-LOCATIVE 100370124> out of STACK-AREA

SYS:COPY-IF-NECESSARY
   Arg 0 (SI:THING): #<DTP-LOCATIVE 100370124>
   Arg 1: 4
s-A, :    Return to Lisp Top Level in Dynamic Lisp Listener 1
s-B:           Restart process Dynamic Lisp Listener 1
 Eval (program): (let ((x 0)) (defun baz () x))[Abort]
Back to Error: Don't know how to copy #<DTP-LOCATIVE 100370124> out of STACK-AREA
 Abort Abort
Return to Lisp Top Level in Dynamic Lisp Listener 1
Back to Lisp Top Level in Dynamic Lisp Listener 1.

  (defun baz () 1)
For Function BAZ
  Function BAZ is being redefined with an unsafeguarded definition.
  Its previous definition was safeguarded.
BAZ
  (defun baz () 1)
BAZ
  (let ((x 0)) (defun baz () x))
BAZ
  
-------