Standard Deviation of a list of integers in Scheme.
Write two expressions to solve this problem:
- First expression, Compute the sum of the squares of the difference between > each number and the population average
- Second, Using that number calculate the standard deviation.
My code so far:
(define (average lst)
(/ (apply + lst) (length lst)))
(define (std-dev lst)
(sqrt
(/
(innerFunction lst (average lst))
(length lst)
)
)
)
(define (innerFunction lst avg)
(if
(null? lst)
0
(+
(*
(- (car lst) avg)
(- (car lst) avg)
)
(innerFunction (cdr lst) average)
)
)
)
(error is "number required, but got #Closure").
I've only started Scheme a week ago so I am not very familiar with it, do you see what's wrong with my code? and how do I fix it, also is there a simpler way to do this possibly with mapping like how I simplified average with apply?
innerFunctioncan be coded as a call tomap. - Will Ness