Xref: utzoo comp.lang.lisp:3590 comp.lang.scheme:1630 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!briscoe-duke From: briscoe-duke@cs.yale.edu (Duke Briscoe) Newsgroups: comp.lang.lisp,comp.lang.scheme Subject: Re: Adding items to the end of a list. Message-ID: <26014@cs.yale.edu> Date: 5 Sep 90 17:44:12 GMT References: <1990Sep5.011910.1177@mentor.com> Sender: news@cs.yale.edu Followup-To: comp.lang.lisp Organization: Yale University Computer Science Dept., New Haven, CT 06520-2158 Lines: 26 Nntp-Posting-Host: pullback.systemsz.cs.yale.edu Originator: briscoe@pullback.CS.Yale.Edu In article <1990Sep5.011910.1177@mentor.com> Patrick Logan writes: >I see a lot of LISP code building lists backwards and then reversing >them. I don't know if I've ever seen any C code doing that. Is it too >easy to write sloppy code in LISP? I don't think it is any more >difficult to write efficient list manipulations in Scheme than it is >in C. > I did some timings on compiled T code, and the difference between copying a list using your copy-list function and using a function (define (dcl lis) (reverse! (reverse lis))) was only 20%, the important thing being that this is an algorithmic difference of a small constant factor. The reverse functions in T are coded in T, not hand-coded assembly by the way. If the operations used to build the elements of the list are expensive (just copying the elements is the least expensive thing I can think of) then the reverse! step is going to make relatively less of a percentage difference. I think in many cases there isn't going to be much difference. If someone is using reverse instead of reverse! then that could be more serious because of the extra consing. I think the important thing is that the standard functions be coded efficiently, but for most user applications a person doesn't need to get involved with potentially tricky pointer manipulations. Duke