Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help on lisp

5 views
Skip to first unread message

darkelf2099

unread,
Feb 23, 2005, 6:46:25 AM2/23/05
to
how do i define a function to add up numbers in a list???

and

a function to compute the average(mean) of a list of numbers

darkelf2099

unread,
Feb 23, 2005, 7:09:41 AM2/23/05
to

Pascal Bourguignon

unread,
Feb 23, 2005, 12:06:07 PM2/23/05
to
darke...@gmail.com (darkelf2099) writes:

(This newsgroup is kind of deprecated. Try: comp.lang.lisp)

> how do i define a function to add up numbers in a list???

In Common-Lisp:

(defun add-up (list)
(reduce (function +) list))



> and
>
> a function to compute the average(mean) of a list of numbers

(defun average (list)
(and list
(/ (reduce (function +) list) (length list))))

--
__Pascal Bourguignon__ http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w---
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++
G e+++ h+ r-- z?
------END GEEK CODE BLOCK------

0 new messages