[comp.lang.lisp.x] Yet Another Xlisp Bug

toma@tekgvs.LABS.TEK.COM (Tom Almy) (11/30/90)

I would like feedback from this group. Please send "votes" on the question
posed at the end of this posting to me.

I found bugs, or at least Common Lisp incompatibilities, with the execution
environments used in EVAL and EVALHOOK. In the code

(setq x 10)

(let ((x 5)) (eval 'x))

the EVAL function returns 10 in Common Lisp because the global (null)
environment is used, while in XLISP the value 5 is returned because
the lexical environment is used. I can put up with this, because I
make use of the ability to evaluate in the current environment (see
later in this posting). 

I recently wanted to evaluate some expressions in the global environment
so I tried using EVALHOOK with a NIL environment, as in:

(setq x 10)

(let ((x 5)) (evalhook 'x nil nil))

and was suprised to find that the lexical environment was used! This is
certainly a bug, because if the environment is specified as '(nil) instead
of just nil then 10 is returned, as in Common Lisp.


My best guess of what to do is to fix EVALHOOK so that a nil environment
is just that (and not the lexical environment), but to leave EVAL the same
becuase otherwise there is no way to evaluate expressions in the lexical
environment!

For debugging purposes, I wanted to be able to set any object instance
variable. To do that I put the following method definition in every
class:

(send classname :answer :set-ivar
		'(ivar value)
		'((eval (list 'setq ivar (list 'quote value)))))

so that to set instance variable foo of object x to '(a b c) one would 
execute:

(send x :set-ivar 'foo '(a b c))

then (setq foo '(a b c)) will be evaluated in the context of the object
and the instance variable gets set.

With the Common Lisp compliant version, EVAL could not be used because a
null environment would be used for evaluation. Likewise EVALHOOK could not
be used. The obvious technique, from my early experience, would be:

(send classname :answer :set-ivar
		'(ivar value)
		'((set ivar value)) )

but, alas, SET is also defined to ignore lexical scoping both in Common Lisp
and in the XLISP implementation.

APPLY and FUNCALL won't work with SETQ, since SETQ is a special form.

So folks, it looks hopeless.


*QUESTION*  What should be done?

Alternatives:


1) Leave the code alone, and use (evalhook expr nil nil '(nil)) to get
   global binding evaluation.

2) "Fix" EVALHOOK only, leaving EVAL non-compliant.

3) "Fix" EVAL only, then EVALHOOK can be used with lexical binding or
   global binding (via the kludge '(nil)).

4) "Fix" both EVAL and EVALHOOK because there is a solution to my lexically
    bound exec problem that I just haven't discovered.


Note, anyone who answers "4" needs to tell me what I am doing wrong!!

The "Fix" for both of these is trivial, BTW, so is not a consideration.




Tom Almy
toma@tekgvs.labs.tek.com
Standard Disclaimers Apply