home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.lisp
- Path: sparky!uunet!pmafire!mica.inel.gov!INEL.GOV!rkf
- From: rkf@INEL.GOV (Raymond K. Fink)
- Subject: Re: Elegant control structure wanted
- Message-ID: <1992Nov19.200850.11967@inel.gov>
- Sender: news@inel.gov
- Reply-To: rkf@inel.gov
- Organization: Idaho National Engineering Laboratory
- References: <98373@netnews.upenn.edu>
- Date: Thu, 19 Nov 92 20:08:50 GMT
- Lines: 45
-
- zaidel@muzungu.cis.upenn.edu (Martin J. Zaidel) writes:
- >I've written an equality predicate to test two structures. My
- >predicate is of the form:
- >
- >(defun node-equal (node1 node2)
- > (and (slot1-equal slot1 slot2)
- > (slot2-equal slot1 slot2)
- > (slot3-equal slot1 slot2)))
- >
- >I wanted to add format statements so that when NODE-EQUAL returned nil,
- >I'd know which slot caused the failure. So I tried UNLESS:
- ...
- >inelegant. I'd appreciate suggestions for a nicer solution.
-
- My suggestion, using the fact that (format ....) returns nil
-
- (defparameter *node-equality-tests*
- '(slot1-equal slot2-equal slot3-equal))
-
- (defun node-equal (node1 node2)
- ;; apply test functions in sequence, returning t if completed ok
- (dolist (fn *node-equality-tests* t)
- (unless (funcall fn node1 node2)
- ;; up and out if a test fails, returning nil and logging message
- (return (format t "Failed on ~A" fn)))))
-
- Pro: easy to modify the list of tests without changing the test function
- Con: may be slower and cons'ier than desirable
-
- --
- Ray Fink -- Idaho National Engineering Laboratory -- Idaho Falls ID
- rkf@inel.gov 208-525-5431
- Hit 'n' now to skip the obnoxious legal disclaimer......
- ========== long legal disclaimer follows, press n to skip ===========
-
- Neither the United States Government or the Idaho National Engineering
- Laboratory or any of their employees, makes any warranty, whatsoever,
- implied, or assumes any legal liability or responsibility regarding any
- information, disclosed, or represents that its use would not infringe
- privately owned rights. No specific reference constitutes or implies
- endorsement, recommendation, or favoring by the United States
- Government or the Idaho National Engineering Laboratory. The views and
- opinions expressed herein do not necessarily reflect those of the
- United States Government or the Idaho National Engineering Laboratory,
- and shall not be used for advertising or product endorsement purposes.
-