Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!dino!ux1.cso.uiuc.edu!cs.uiuc.edu!yonezawa From: yonezawa@cs.uiuc.edu (Noritake Yonezawa) Newsgroups: comp.lang.lisp Subject: Re: Mirror speeds Message-ID: Date: 14 Oct 90 05:56:32 GMT References: <47064@cornell.UUCP> Sender: news@ux1.cso.uiuc.edu (News) Distribution: comp Organization: University of Illinois at Urbana-Champaign Lines: 27 In-Reply-To: raja@copper.ucs.indiana.edu's message of 13 Oct 90 21:21:27 GMT In article raja@copper.ucs.indiana.edu (Raja Sooriamurthi) writes: > Here is a CPSed form of the mirror function. Now all calls to the > auxillary function mir are properly tail recursive and a scheme > implementation (and some CL implementations) would optimize the > recursive calls into jumps. Here is another form of the mirror function. The auxillary functions are CPSed, but not tail recursive. I avoided using 'append'. Does anyone know better solution? (defun mirror (x) (labels ((f1 (x c) (if (atom x) (funcall c x) (f2 x nil c))) (f2 (x y c) (if (null x) (funcall c y) (f1 (car x) #'(lambda (z) (f2 (cdr x) (cons z y) c)))))) (f1 x #'identity))) -- Noritake Yonezawa [yonezawa@cs.uiuc.edu] Department of Computer Science University of Illinois at Urbana-Champaign