average = list ->
  avg list 0 0 0
_
  list : _ : I|F : +-
;  

avg average = list weight divider total ->
  avg tail next-weight next-divider next-total                                 /* "tail rec." */
  ' next-divider = divider + (weight + 1)
  ' next-weight = weight + 1
  ' next-total = total + x * (weight + 1)
  ' x, tail -- detach list x tail
_
  list._ > 0
;

avg average = list weight divider total ->
  if divider -> total / divider
  else 0
_
  list._ = 0
;