2.21

练习 2.21 过程 square-list 以一个数值表为参数,返回每个数的平方构成的表:

(square-list (list 1 2 3 4))
(1 4 9 16)

下面是square-list的两个定义,请填充其中缺少的表达式以完成它们:

(define (square-list items)
    (if (null? items)
        nil
        (cons <??> <??>)))

(define (square-list items)
    (map <??> <??>))

(define (square-list items)
    (if (null? items)
        '()
        (cons (* (car items) (car items)) (square-list (cdr items)))))

(square-list (list 1 2 3 4))
(define (square-list-2 items)
    (map (lambda (x) (* x x)) items))

(square-list-2 (list 1 2 3 4))

results matching ""

    No results matching ""