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

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!pmafire!mica.inel.gov!INEL.GOV!rkf
  3. From: rkf@INEL.GOV (Raymond K. Fink)
  4. Subject: Re: Elegant control structure wanted
  5. Message-ID: <1992Nov19.200850.11967@inel.gov>
  6. Sender: news@inel.gov
  7. Reply-To: rkf@inel.gov
  8. Organization: Idaho National Engineering Laboratory
  9. References:  <98373@netnews.upenn.edu>
  10. Date: Thu, 19 Nov 92 20:08:50 GMT
  11. Lines: 45
  12.  
  13. zaidel@muzungu.cis.upenn.edu (Martin J. Zaidel) writes:
  14. >I've written an equality predicate to test two structures.  My
  15. >predicate is of the form:
  16. >
  17. >(defun node-equal (node1 node2)
  18. >   (and (slot1-equal slot1 slot2)
  19. >    (slot2-equal slot1 slot2)
  20. >    (slot3-equal slot1 slot2)))
  21. >
  22. >I wanted to add format statements so that when NODE-EQUAL returned nil,
  23. >I'd know which slot caused the failure.  So I tried UNLESS:
  24. ...
  25. >inelegant.  I'd appreciate suggestions for a nicer solution.
  26.  
  27. My suggestion, using the fact that (format ....) returns nil
  28.  
  29. (defparameter *node-equality-tests*
  30.   '(slot1-equal slot2-equal slot3-equal))
  31.  
  32. (defun node-equal (node1 node2)
  33.   ;; apply test functions in sequence, returning t if completed ok
  34.   (dolist (fn *node-equality-tests* t)
  35.     (unless (funcall fn node1 node2)
  36.        ;; up and out if a test fails, returning nil and logging message
  37.        (return (format t "Failed on ~A" fn)))))
  38.  
  39. Pro: easy to modify the list of tests without changing the test function
  40. Con: may be slower and cons'ier than desirable
  41.  
  42. --
  43. Ray Fink -- Idaho National Engineering Laboratory -- Idaho Falls ID 
  44.     rkf@inel.gov            208-525-5431
  45. Hit 'n' now to skip the obnoxious legal disclaimer......
  46. ========== long legal disclaimer follows, press n to skip ===========
  47.  
  48. Neither the United States Government or the Idaho National Engineering
  49. Laboratory or any of their employees, makes any warranty, whatsoever,
  50. implied, or assumes any legal liability or responsibility regarding any
  51. information, disclosed, or represents that its use would not infringe
  52. privately owned rights.  No specific reference constitutes or implies
  53. endorsement, recommendation, or favoring by the United States
  54. Government or the Idaho National Engineering Laboratory.  The views and
  55. opinions expressed herein do not necessarily reflect those of the
  56. United States Government or the Idaho National Engineering Laboratory,
  57. and shall not be used for advertising or product endorsement purposes.
  58.