【发布时间】:2015-05-10 23:11:49
【问题描述】:
我是 Lisp 新手,需要帮助了解此功能以及对 (map length '((a b c) (1 2 3 4 5) (v1 v2 v3 v4 v5 v6)))) 的评估
值为(3 5 6)
(define (map f list)
; applies function f to each element of list
(if (null? list)
()
(cons (f (car list))
(map f (cdr list)))))
(define map-test-1
(map square '(1 2 3 4 5)))
(define map-test-2
(map length '((a b c) (1 2 3 4 5) (v1 v2 v3 v4 v5 v6))))
【问题讨论】:
-
表达式 (cons (f (car list)) (map f (cdr list))))) 以及它在 map-test-2 中如何计算为 (3 5 6)
-
是的,可能还需要更清楚
-
是的,所以对于 map-test-2,它会是 (cons (length a) (map length '( b c)) cons (length 1) (map length '(2 3 4 5 )) cons (length v1) (map length '(v2 v3 v4 v5 v6)) 等等