home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / 2917 < prev    next >
Encoding:
Text File  |  1992-11-19  |  1.8 KB  |  54 lines

  1. Path: sparky!uunet!ogicse!uwm.edu!spool.mu.edu!umn.edu!saturn.cs.umn.edu!konstan
  2. From: konstan@saturn.cs.umn.edu (Joe Konstan)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Elegant control structure wanted
  5. Message-ID: <1992Nov19.182342.17095@news2.cis.umn.edu>
  6. Date: 19 Nov 92 18:23:42 GMT
  7. Article-I.D.: news2.1992Nov19.182342.17095
  8. References: <98373@netnews.upenn.edu>
  9. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  10. Organization: Department of Computer Science, University of Minnesota
  11. Lines: 40
  12. Nntp-Posting-Host: saturn.cs.umn.edu
  13.  
  14. In article <98373@netnews.upenn.edu>, zaidel@muzungu.cis.upenn.edu (Martin J. Zaidel) is trying to modify
  15. |> (defun node-equal (node1 node2)
  16. |>    (and (slot1-equal slot1 slot2)
  17. |>     (slot2-equal slot1 slot2)
  18. |>     (slot3-equal slot1 slot2)))
  19. to add format statements to show which slot triggered the inequality.
  20.  
  21. It seems to me that you have two choices, each of which could add a
  22. bit of elegance.  First, if you are willing to modify slot-1-equal, ..., 
  23. I would suggest putting the format in there (possibly controlled by
  24. an optional parameter):
  25.  
  26.     (defun slot1-equal (x y &optional (fmt? nil))
  27.           ...)
  28.  
  29. If this is inappropriate, then I'd go back to basics and use cond.  Recall
  30. that format always returns nil (except for (format nil ...), p 581 CLtL2), so:
  31.  
  32.     (defun node-equal (node1 node2)
  33.           (cond ((not (slot1-equal node1 node2)) (format t "Slot 1"))
  34.                 ((not (slot2-equal node1 node2)) (format t "Slot 2"))
  35.                 (t t)))
  36.  
  37. Another choice to consider is not using format at all, but instead trying one
  38. of the following:
  39.  
  40. 1.  Use values to return multiple values--namely t or nil and when nil the
  41.     slot that failed.
  42.  
  43. 2.  Write the inverse
  44.  
  45.     (defun difference (node1 node2)
  46.     ....
  47.  
  48.     so that it returns nil when they are equal and the slot name when they 
  49.     aren't.
  50.  
  51.  
  52. Joe Konstan
  53. konstan@cs.umn.edu
  54.