Subject: Re: A function-generating function question.
From: Erik Naggum <>
Date: 02 Nov 2002 17:42:05 +0000
Newsgroups: comp.lang.lisp
Message-ID: <>

* 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 <function> ...).

  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.