From Newsgroup: comp.lang.lisp
Tim Bradshaw wrote:
(defun avg (args)
(loop for x in args
for l upfrom 1
summing x into tot
finally (return (/ tot l))))
It's shorter if one uses a Lispy language.
Gauche Scheme:
(define (avg nums)
(apply /
(fold
(^(x xs) (map + `(,x 1) xs))
'(0 0)
nums)))
(avg '(2))
2
(avg '(2 3))
5/2
(avg '(2 3 4))
3
(avg '(2 3 4 5.0))
===>
3.5
--
[T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
--- Kenny Tilton
The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2