Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!altair!halvers From: halvers@altair.crd.ge.com (Pete Halverson) Newsgroups: comp.lang.lisp Subject: Re: another question, arrays Message-ID: <20101@crdgw1.crd.ge.com> Date: 31 May 91 13:56:45 GMT References: <43929@netnews.upenn.edu> <13228@ptolemy-ri.arc.nasa.gov> Sender: news@crdgw1.crd.ge.com Reply-To: halverson@crd.ge.com (Pete Halverson) Distribution: na Organization: General Electric Corporate R&D Center Lines: 36 In article <13228@ptolemy-ri.arc.nasa.gov> chucko@ptolemy.arc.nasa.gov (Chuck Fry) writes: >In article <43929@netnews.upenn.edu> vinson@linc.cis.upenn.edu (Jack Vinson) writes: >>Me again, I am also playing with arrays for the first time in lisp and am >>wondering what kind of interesting functions there are for messing with them. >>In particular I will be frequently updating one array by moving elements down >>into the array. ie if the array is (1.2 1.1 1.2 1.3 1.1 1.0) and new data is >>1.2 I want to put the new info at the 'beginning' of the array and shift >>everything down, so I would get (1.2 1.2 1.1 1.2 1.3 1.1) with the last >>element knocked off. The way I know how to do this is with a do-loop >>that copies element i into i+1, starting from the highest element. > >CLtL provides a facility for dealing with vectors (simple arrays) as >stacks [using VECTOR-PUSH and VECTOR-POP]. >If the most recent must be the 0th element, you're pretty much stuck >with the DO-loop approach. You can also use the REPLACE function to shift stuff around, e.g. (replace my-array my-array :start1 1) should behave the same as (loop for i from (1- (length my-array)) downto 1 do (setf (aref my-array i) (aref my-array (1- i)))) and is hopefully (?) better optimized. Pete -- =============================================================================== Pete Halverson INET: halverson@crd.ge.com GE Corporate R&D Center UUCP: uunet!crd.ge.com!halverson Schenectady, NY