Subject: Re: Request for comments on CLOS code
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 30 Aug 2004 20:55:23 -0500
Newsgroups: comp.lang.lisp
Message-ID: <i92dnaTM3O8WR67cRVn-tw@speakeasy.net>
Peter Lewerin <peter.lewerin@swipnet.se> wrote:
+---------------
| peter.lewerin@swipnet.se (Peter Lewerin) wrote
| > Of course.  With this added requirement, a tail slot makes sense:
| 
| Ooops.  Forgot to null the tail slot when the last element is
| dequeued.  (Actually, it doesn't matter, but anyway.)
| 
|     (defmethod dequeue :after ((q constant-time-fifo))
|       (with-slots (contents tail) q
|         (unless contents
|           (setf tail nil))))
+---------------

Alternatively, you could just as easily do that right
in the primary method itself:

    (defmethod dequeue ((q constant-time-fifo))
      (with-slots (contents tail) q
	(prog1
	 (pop contents)
	 (unless contents
	   (setf tail nil)))))

That way, somebody reading your code doesn't have to
go looking for the :AFTER method. [Plus, it's likely
to be somewhat faster as well.]

Note: I don't have anything against :AFTER methods in
general, but it seems a bit excessive in this case.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607