home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / mcl / 1191 next >
Encoding:
Text File  |  1992-08-12  |  1.6 KB  |  45 lines

  1. Path: sparky!uunet!olivea!apple!apple!cambridge.apple.com!drh@world.std.com
  2. From: drh@world.std.com (Denis R Howlett)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: Apply
  5. Message-ID: <Pine.2.4.9208120903.C3912@world.std.com>
  6. Date: 12 Aug 92 13:40:01 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 33
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Original-To: MacLisp Info Line <info-macl@cambridge.apple.com>
  11.  
  12. I too discovered that apply and funcall don't work for lambda lists any
  13. more and was rather disheartened since a great deal of our user interface
  14. code relies on constructing functions which are then attached to buttons.
  15.  
  16. Much of this code is created with backquotes so that variables can be
  17. insterted, a simple example might be:
  18.  
  19. (defun make-menu-items (items)
  20.   (let (menu-items)
  21.     (dolist (item items)
  22.       (push (make-instance ...
  23.                            :attached-function
  24.                            `(lambda (window)
  25.                   (declare (ignore window))
  26.                               (print ',item)))))))
  27.  
  28. I know the code isn't quite right but you get the idea, each lambda
  29. expression is created at run time.
  30.  
  31. The solution I have adopted (but don't like) is to make the function
  32. dispatcher more intelligent and do the following:
  33.  
  34. ;; attached-function & window are bound in preceding lines
  35.   (funcall (if (listp attached-function)
  36.               (eval `(function ,attached-function))
  37.               attached-function)
  38.            window)
  39.  
  40. This allows my dispatcher to deal with all the things that funcall (and
  41. apply used to deal with), but I always thought it was bad form to use eval
  42. in the middle of code? ...
  43.  
  44. Denis
  45.