Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!cs.uiuc.edu!yonezawa From: yonezawa@cs.uiuc.edu (Noritake Yonezawa) Newsgroups: comp.lang.lisp Subject: Re: novice question Message-ID: Date: 13 Oct 90 14:58:46 GMT References: <90285.160549JEFHC@CUNYVM.BITNET> <3315@idunno.Princeton.EDU> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana-Champaign Lines: 27 In-Reply-To: eliot@phoenix.Princeton.EDU's message of 13 Oct 90 04:05:04 GMT In article <3315@idunno.Princeton.EDU> eliot@phoenix.Princeton.EDU (Eliot Handelman) writes: > Try this, which slightly generalizes the trick of consing up the > reversed list in an accumulator: > > (defun mirror (list) > (labels ((mirror-1 (list accumulator) > (cond ((endp list) accumulator) > ((atom (car list)) > (mirror-1 (cdr list) > (cons (car list) accumulator))) > (t (mirror-1 (cdr list) > (cons (mirror-1 (car list) nil) > accumulator)))))) > (mirror-1 list nil))) How about this? (defun mirror (x) (if (atom x) x (reverse (mapcar #'mirror x)))) -- Noritake Yonezawa [yonezawa@cs.uiuc.edu] Department of Computer Science University of Illinois at Urbana-Champaign