home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / XLSP21TC.ZIP / XL-003.BUG / text0000.txt < prev   
Encoding:
Text File  |  1991-04-14  |  2.8 KB  |  86 lines

  1. In looking over the xlisp 2.0 objects code, I found a problem in
  2. xlobj.c:clanswer() in which I noticed that the :answer method on class
  3. Class does not save the lexical (xlenv) and functional (xlfenv)
  4. environments in the closure created by xlclose() during method definition.
  5. Thus, when the method gets evaluated, you get unbound symbol/function
  6. errors because the environment of the method call doesn't contain the
  7. bindings present in the definition's environment.  [For you non xlispers
  8. out there, :answer defines a method on a class (essentially, a
  9. "defmethod").]
  10.  
  11. Before I commit to my fix, I wanted to ask you all whether there is a good
  12. reason for NOT using the lexical and functional environment of a call to
  13. "defmethod" during a method evaluation.
  14.  
  15. I would expect that you'd want to use lexical scoping for defining methods
  16. just like you would for defuns and lambdas. But I've been surprised before.
  17.  
  18. Another case in which xlclose() isn't passed xlenv and xlfenv is in
  19. xlcont.c:xdefmacro(). Is there a reason why you wouldn't want to pass
  20. in the lexical environment of a call to defmacro?
  21.  
  22.                 ----------
  23.  
  24. Here's some useless test code that illustrates the problem:
  25.  
  26.     lisp> (setq test_class (send Class :new '(a b c) '()))
  27.     lisp> (let (
  28.                 (x 666)
  29.                 (y 777)
  30.                 (z 888))
  31.             (send test_class :answer :isnew '()  ;initialize method
  32.             '(
  33.            (setq a x)
  34.            (setq b y)
  35.            (setq c z)
  36.            ))
  37.             )
  38.     lisp> (setq i (send test_class :new))
  39.  
  40. Now, upon sending the :new message, I get the error mesage
  41.  
  42.     lisp> error: unbound variable - X
  43.  
  44. After fixing the code in xlobj.c:clanswer(), I get the correct results:
  45.  
  46.     lisp> (send i :show)
  47.     lisp> Object is #<Object: #136002>, Class is #<Object: #127f40>
  48.     lisp>   A = 666
  49.     lisp>   B = 777
  50.     lisp>   C = 888
  51.     lisp> #<Object: #136002>
  52.  
  53.                 ----------
  54.  
  55. Here's the patch:
  56.  
  57. *** xlobj.c.~1~    Sat Aug 26 06:14:33 1989
  58. --- xlobj.c    Sat Aug 26 06:16:24 1989
  59. ***************
  60. *** 277,283
  61.       /* setup the message node */
  62.       xlprot1(fargs);
  63.       fargs = cons(s_self,fargs); /* add 'self' as the first argument */
  64. !     rplacd(mptr,xlclose(msg,s_lambda,fargs,code,NIL,NIL));
  65.       xlpop();
  66.   
  67.       /* return the object */
  68.  
  69. --- 277,283 -----
  70.       /* setup the message node */
  71.       xlprot1(fargs);
  72.       fargs = cons(s_self,fargs); /* add 'self' as the first argument */
  73. !     rplacd(mptr,xlclose(msg,s_lambda,fargs,code,xlenv,xlfenv));    /* changed by NPM -- pass in lexical and functional environment */
  74.       xlpop();
  75.   
  76.       /* return the object */
  77.  
  78. -------------------------------------------------------------------------------
  79.         Niels Mayer -- hplabs!mayer -- mayer@hplabs.hp.com
  80.           Human-Computer Interaction Department
  81.                Hewlett-Packard Laboratories
  82.                   Palo Alto, CA.
  83.                    *
  84.  
  85.  
  86.