B. Pym
2024-09-19 07:32:45 UTC
(defun average-function (list)
(assert list (list)
"List should not be empty.")
(loop for i from 0
for item in list
sum item into result
finally (return (/ result i))))
It's shorter in Gauche Scheme.(assert list (list)
"List should not be empty.")
(loop for i from 0
for item in list
sum item into result
finally (return (/ result i))))
(define (average-function lst)
(let1 n 0
(/ (fold (lambda (x sum) (inc! n) (+ x sum)) 0 lst)
n)))