home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!spool.mu.edu!umn.edu!saturn.cs.umn.edu!konstan
- From: konstan@saturn.cs.umn.edu (Joe Konstan)
- Newsgroups: comp.lang.lisp
- Subject: Re: Elegant control structure wanted
- Message-ID: <1992Nov19.182342.17095@news2.cis.umn.edu>
- Date: 19 Nov 92 18:23:42 GMT
- Article-I.D.: news2.1992Nov19.182342.17095
- References: <98373@netnews.upenn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Organization: Department of Computer Science, University of Minnesota
- Lines: 40
- Nntp-Posting-Host: saturn.cs.umn.edu
-
- In article <98373@netnews.upenn.edu>, zaidel@muzungu.cis.upenn.edu (Martin J. Zaidel) is trying to modify
- |> (defun node-equal (node1 node2)
- |> (and (slot1-equal slot1 slot2)
- |> (slot2-equal slot1 slot2)
- |> (slot3-equal slot1 slot2)))
- to add format statements to show which slot triggered the inequality.
-
- It seems to me that you have two choices, each of which could add a
- bit of elegance. First, if you are willing to modify slot-1-equal, ...,
- I would suggest putting the format in there (possibly controlled by
- an optional parameter):
-
- (defun slot1-equal (x y &optional (fmt? nil))
- ...)
-
- If this is inappropriate, then I'd go back to basics and use cond. Recall
- that format always returns nil (except for (format nil ...), p 581 CLtL2), so:
-
- (defun node-equal (node1 node2)
- (cond ((not (slot1-equal node1 node2)) (format t "Slot 1"))
- ((not (slot2-equal node1 node2)) (format t "Slot 2"))
- (t t)))
-
- Another choice to consider is not using format at all, but instead trying one
- of the following:
-
- 1. Use values to return multiple values--namely t or nil and when nil the
- slot that failed.
-
- 2. Write the inverse
-
- (defun difference (node1 node2)
- ....
-
- so that it returns nil when they are equal and the slot name when they
- aren't.
-
-
- Joe Konstan
- konstan@cs.umn.edu
-