sub sum { my($term, $a, $next, $b) = @_; return 0 if $a > $b; return &$term($a) + sum($term, &$next($a), $next, $b); }