Subject: Re: simple-array vs displaced-to From: Erik Naggum <email@example.com> Date: 17 Jan 2004 21:38:04 +0000 Newsgroups: comp.lang.lisp Message-ID: <3283364284060266KL2065E@naggum.no> * Martin Raspaud | One would say "why not give as parameter to the processing funtion | the big array and an offset ?" Well, I don't really like this, it | doesn't feel the right way to do it to me. | | So am I wrong with this or is there another solution, ie having a kind | of displaced-to array that would be a simple-array ? One common optimization when working with non-simple arrays is to dig out the underlying simple-array and the start and end positions that a displaced array makes into one convenient object. The function ARRAY-DISPLACEMENT returns the values of the arguments :DISPLACED-TO and and :DISPLACED-INDEX-OFFSETgiven to MAKE-ARRAY or ADJUST-ARRAY, or NIL and 0 if it was not displaced. (defun undisplace-array (array) "Return the fundamental array and the start and end positions into it of a displaced array." (let ((length (length array)) (start 0)) (loop (multiple-value-bind (to offset) (array-displacement array) (if to (setq array to start (+ start offset)) (return (values array start (+ start length)))))))) -- Erik Naggum | Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.