Prev: floating point output?
Next: free will
From: Krishna Myneni on 25 Jul 2010 11:57 Apologies in advance if this is a naive question, since I'm new to Lisp (my background is Forth). Is there an intrinsic function in Common Lisp which will iterate over each element of the list and apply a binary function between an integer and the list element. The return value should be an integer. I'm familiar with "mapcar", "every", and "some", but I can't see how to adapt them to this problem. I realize one can write such a list iterator, but my question is whether or not such a function already exists, or, if not, whether there is a commonly accepted name for such an iterator. Thanks. Krishna -- Example: (accum 0 '+ '( 1 2 3 ) ) with the result being 6.
From: Pascal Costanza on 25 Jul 2010 11:58 On 25/07/2010 17:57, Krishna Myneni wrote: > Apologies in advance if this is a naive question, since I'm new to > Lisp (my background is Forth). > > Is there an intrinsic function in Common Lisp which will iterate over > each element of the list and apply a binary function between an > integer and the list element. The return value should be an integer. > I'm familiar with "mapcar", "every", and "some", but I can't see how > to adapt them to this problem. I realize one can write such a list > iterator, but my question is whether or not such a function already > exists, or, if not, whether there is a commonly accepted name for such > an iterator. Thanks. > > Krishna > > -- > Example: > > (accum 0 '+ '( 1 2 3 ) ) > > with the result being 6. It's called 'reduce. Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Frank Buss on 25 Jul 2010 12:02 Krishna Myneni wrote: > Apologies in advance if this is a naive question, since I'm new to > Lisp (my background is Forth). > > Is there an intrinsic function in Common Lisp which will iterate over > each element of the list and apply a binary function between an > integer and the list element. The return value should be an integer. > I'm familiar with "mapcar", "every", and "some", but I can't see how > to adapt them to this problem. I realize one can write such a list > iterator, but my question is whether or not such a function already > exists, or, if not, whether there is a commonly accepted name for such > an iterator. Thanks. Yes, reduce: CL-USER 1 > (reduce #'+ '(1 2 3) :initial-value 10) 16 CL-USER 2 > -- Frank Buss, fb(a)frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
From: Krishna Myneni on 25 Jul 2010 12:12 On Jul 25, 10:58 am, Pascal Costanza <p...(a)p-cos.net> wrote: > On 25/07/2010 17:57, Krishna Myneni wrote: > > > > > Apologies in advance if this is a naive question, since I'm new to > > Lisp (my background is Forth). > > > Is there an intrinsic function in Common Lisp which will iterate over > > each element of the list and apply a binary function between an > > integer and the list element. The return value should be an integer. > > I'm familiar with "mapcar", "every", and "some", but I can't see how > > to adapt them to this problem. I realize one can write such a list > > iterator, but my question is whether or not such a function already > > exists, or, if not, whether there is a commonly accepted name for such > > an iterator. Thanks. > > > Krishna > > > -- > > Example: > > > (accum 0 '+ '( 1 2 3 ) ) > > > with the result being 6. > > It's called 'reduce. > > Pascal > > -- > My website:http://p-cos.net > Common Lisp Document Repository:http://cdr.eurolisp.org > Closer to MOP & ContextL:http://common-lisp.net/project/closer/ Thanks, Pascal and Frank! Krishna
|
Pages: 1 Prev: floating point output? Next: free will |