From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed1.bredband.com!bredband!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: A function-generating function question. Date: 02 Nov 2002 17:42:05 +0000 Organization: Naggum Software, Oslo, Norway Lines: 24 Message-ID: <3245247725231909@naggum.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: maud.ifi.uio.no 1036258926 9429 129.240.65.211 (2 Nov 2002 17:42:06 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 2 Nov 2002 17:42:06 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:45517 * rif | I have a list of lists of integers l (example: ((3 5) (1 2 3))), and I | want to generate a function that takes an array arr and returns a new | array whose i'th element is the product of the elements of arr indexed by | the i'th element of l. To make a new vector that contains the values of some function applied to each element of a list in order, you can use (map 'vector ...). To produce a product of all values in a list, you can use (reduce #'* ...). To extract the nth item from a vector and use it instead of n, use an accessor function and specify this function as the key to reduce. (map 'vector (lambda (l) (reduce #'* l :key (lambda (n) (aref v n))))) If this is not fast enough, you may want to optimize only some components instead of writing the whole thing out in full by hand. -- 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.