In addition to this static demo, I also have a live demo here.

# The program is:

## Basic list functions
# Using function f and starting value z, run the function forward for each
# element in the list.
\fold=
(\f @\loop \z\xs
xs z \x\xs
\z=(f z x)
loop z xs
)
# Apply f to each element in list xs.
\map=
(\f @\loop \xs
xs [] \x\xs
\x=(f x)
\tail=(once; loop xs)
[x;tail]
)
# Do f for each item in list xs.
\each=
(\xs\f
(@\loop\xs xs () \x\xs f x loop xs)
xs
)
## Statistical functions
\list_sum=(fold + 0)
\list_length=(fold (\n\_ + 1 n) 0)
\list_mean=(\xs / (list_sum xs) (list_length xs))
\list_variance=
(\list
\mean=(list_mean list)
\diff=(map (\val - val mean) list)
\square_diff=(map (\val * val val) diff)
list_mean square_diff
)
\list_stddev=(\list sqrt; list_variance list)
## Output functions
\p=(say "<p>")
\pre=(\body say "<pre>" body say "</pre>")
\show=
(\label\val
put [label " = "]
is_list val
(each val \x put [x " "])
(put val)
nl
)
## (show_stats list) Shows the statistics for the given list.
\show_stats=
(\list
p
say ~
<h2> Show Stats </h2>
First call the list_stddev function directly to get the final answer.
~
pre
(
show "list" list
\stddev=(list_stddev list)
show "stddev" stddev
)
p
say ~
Now show how we arrive at that answer.
~
pre
(
\sum=(list_sum list)
\count=(list_length list)
\mean=(list_mean list)
show "list" list
show "sum" sum
show "count" count
show "mean" mean
\diff=(map (\val - val mean) list)
\square_diff=(map (\val * val val) diff)
show "diff" diff
show "square_diff" square_diff
\variance=(list_mean square_diff)
show "variance" variance
\stddev=(sqrt variance)
show "stddev" stddev
)
)
# Now show the stats for a couple of lists.
show_stats [2 4 4 4 5 5 7 9]
show_stats [-11 0 6]

# The output is:

## Show Stats

First call the list_stddev function directly to get the final answer.

list = 2 4 4 4 5 5 7 9
stddev = 2

Now show how we arrive at that answer.

list = 2 4 4 4 5 5 7 9
sum = 40
count = 8
mean = 5
diff = -3 -1 -1 -1 0 0 2 4
square_diff = 9 1 1 1 0 0 4 16
variance = 4
stddev = 2

## Show Stats

First call the list_stddev function directly to get the final answer.

list = -11 0 6
stddev = 7.03957069398096

Now show how we arrive at that answer.

list = -11 0 6
sum = -5
count = 3
mean = -1.66666666666667
diff = -9.33333333333333 1.66666666666667 7.66666666666667
square_diff = 87.1111111111111 2.77777777777778 58.7777777777778
variance = 49.5555555555556
stddev = 7.03957069398096