Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

how do I average in scheme?

Name: Anonymous 2010-12-26 21:31

im learning scheme and im not very good its my first languages what am i doing wrong

(define (average nums)
   (/ (+ (car nums) (average (cdr nums))) 2))

then i do (average (list 2 3 4 5 6)) but it doesnt work
also how can i do that (average 2 3 4 5 6) gives me the average without doing a list?

please help

Name: Anonymous 2010-12-26 22:32

>>1,3
I've done it for you:
((((((λ(d)(λ(p)(λ(e)(λ(i)(λ(n)(d(n e p)(n i)))))))/)+)5)4)((((((((((λ(a)(λ(r)(λ(d)(λ(m)(λ(p)(λ(g)(λ(vr)(λ(v)(λ l((λ(j)((λ e((λ(f)(λ(z . o)(a(vr f z)o)))(a v e)))(λ(a)(set! j(+ j 1))(set! l(m l a)))(λ()(r l))(λ()(d l))(λ()(p j l))(λ()j)(λ(f)(a f l))))(g l)))))))))))apply)car)cdr)cons)(λ(j l)(or(zero? j)(null? l))))length)vector-ref)vector)1 2 3 4 5))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List