Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!stanford.edu!ptolemy-ri!chucko From: chucko@ptolemy.arc.nasa.gov (Chuck Fry) Newsgroups: comp.lang.lisp Subject: Re: another question, arrays Message-ID: <13228@ptolemy-ri.arc.nasa.gov> Date: 31 May 91 00:43:33 GMT References: <43929@netnews.upenn.edu> Sender: usenet@ptolemy-ri.arc.nasa.gov Distribution: na Organization: Recom Technologies, NASA Ames Research Center, Moffett Field, CA Lines: 32 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. If you don't mind the nth element of the array being most recent instead of the 0th, you can use VECTOR-PUSH or VECTOR-PUSH-EXTEND on an array with a fill-pointer. VECTOR-PUSH-EXTEND adjusts the array if the initial array size is exceeded, providing you created the array with :ADJUSTABLE T to begin with. Then VECTOR-POP can destructively access the most recent element, or (AREF stack (1- (FILL-POINTER stack))) will do the same thing non-destructively. If the most recent must be the 0th element, you're pretty much stuck with the DO-loop approach. Chuck Fry Chucko@Charon.ARC.NASA.GOV ...ames!ptolemy!chucko Disclaimer: No one but me is responsible for this misinformation. "Sun is in an ideal situation. It has convinced the market that open technology is the best. Yet, the company narrows its own interpretation of 'open' as its market share and technology advantages expands." -- "The Fifth Architecture", Mark Hall, in SunWorld, April 1991