Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.scheme Subject: Re: how to write append from primitives? Message-ID: <1991May28.202106.23617@Think.COM> Date: 28 May 91 20:21:06 GMT References: <1650003@hpkslx.mayfield.HP.COM> Sender: news@Think.COM Reply-To: barmar@think.com Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 19 In article <1650003@hpkslx.mayfield.HP.COM> ted@hpkslx.mayfield.HP.COM (Ted Johnson) writes: >How would one write append, using just car, cons, and cdr? Here's a two-argument append. The n-argument version is left as an exercise for the reader: (defun append (list1 list2) (if (null list1) list2 (cons (car list1) (append (cdr list1) list2)))) Unfortunately, this isn't tail recursive. It could be made so without too much work, but I don't feel like doing it at the moment. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar