I wanted to make a function that calculates the average of a list of that is a mixture of integers and lists of integers. for example: (= test (list 1 2 3 (list 3 4 5) (list 3 4 (list 1 2 3))))
would resolve to 1+2+3+(resolves to 4)+(resolves to 3) / 5 = 13 / 5.I wrote a function for that which works, but I'm curious how you'd write it. Often there's something to learn of alternative implementations, especially since I'm a lisp-newbie.. =). (def dothis (li)
(with (sum 0 size (len li))
(map1 (fn (_)
(if (is (type _) 'cons) (= sum (+ sum (dothis _))) (= sum (+ sum _))))
li)
(/ sum size)))
works! |