From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!npeer.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: How to reverse a list... References: <5b829932.0112030950.3f96120b@posting.google.com> <3C0C09D7.AB4C24F5@isomedia.com> Mail-Copies-To: never From: Erik Naggum Message-ID: <3216418834714099@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 46 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 04 Dec 2001 01:40:36 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader1.kpnqwest.net 1007430036 193.71.66.49 (Tue, 04 Dec 2001 02:40:36 MET) NNTP-Posting-Date: Tue, 04 Dec 2001 02:40:36 MET Xref: archiver1.google.com comp.lang.lisp:21821 * Steve Long | (cond | ((consp seq-in) ...) | ((stringp seq-in) ...) | ((vectorp seq-in) ...) | (t (error "MY-REVERSE: Arg type ~a not handled." | (type-of seq-in))))) This is what the typecase family is for. Incidentally, (reverse ()) is well-defined. (etypecase seq-in (null nil) ;; special case (cons ...) (string ...) ;; special case (vector ...)) Note that a string is a vector of type character and thet it might not make much of a difference when you have to ensure that you return a vector of the same type as you received, just like the standard says. This is not particularly hard to do: (make-array (length sequence) :element-type (array-element-type sequence)) Since the initial value of the array is irrelevant, you could also use (copy-seq sequence) which does this for you and may be just as fast. Traversing a vector is not particularly hard, either: (do ((forward 0 (1+ forward)) (backward (1- (length vector)) (1- backward)) (reversed (copy-seq sequence))) ((minusp backward) reversed) (setf (aref reversed backward) (aref reversed forward))) (There is no chance that any of this would be useful in homework. :) /// -- The past is not more important than the future, despite what your culture has taught you. Your future observations, conclusions, and beliefs are more important to you than those in your past ever will be. The world is changing so fast the balance between the past and the future has shifted.