chickadee » sicp » ambeval-map

ambeval-map exp env fprocedure
ambeval-map exp env f nprocedure

Maps over the results of up to n successful executions of exp; if n is missing, maps over all successful executions until failure.

exp
The expression to execute
env
The environment to execute it in
f
The function to apply to the results
n
The number of results to gather
(define ambeval-map
  (case-lambda
    ((exp env f) (ambeval-map exp env f +inf.0))
    ((exp env f n)
     (ambeval
       exp
       env
       (lambda (val next-alternative)
         (set! n (- n 1))
         (if (negative? n) '() (cons val (next-alternative))))
       (lambda () '())))))