this is done in scheme racket the scan function scan takes a binary function f a val 5187962
This is done in scheme/racket.
The scan function scan takes a binary function f, a value z, and a list l, and returns the list z,f(x1,z),f(x2,f(x1,z)),…,f(xn,f(xn−1,…))z,f(x1,z),f(x2,f(x1,z)),…,f(xn,f(xn−1,…)) where x1,x2,…,xnx1,x2,…,xn are the elements of the list l.
Examples:
(
scan + 0
'())
=> (0) (
scan + 0
'(1 2 3 4 5 6))
=> (0 1 3 6 10 15 21) (
scan * 1
'(1 2 3 4 5 6))
=> (1 1 2 6 24 120 720)
This may remind you of the reduce function. You can think of scan as a version of reduce that returns a list of the all the intermediate results of the reduction.
(define (scan f z l) | |
#f) |