函数式编程 - Scheme 3
第二十一课
map
> (double-all '(1 2 3 4))
(2 4 6 8)
> (incr-all '(1 2 3 4))
(2 3 4 5)> (define (double x) (* x 2))
> (define (incr x) (+ x 1))
; map unary functions
> (map double '(1 2 3 4))
(2 4 6 8)
> (map incr '(1 2 3 4))
(2 3 4 5)
> (map car '((1 2) (4 8 2) (11)))
(1 4 11)
> (map cdr '((1 2) (4 8 2) (11)))
((2) (8 2) ())
; map binary functions
> (map cons '(1 2 8) '((4) () (2 5)))
((1 4) (2) (8 2 5))
> (map + '(1 2) '(3 4) '(6 10))
(10 16)apply & eval
translate
define named procedure
Last updated