#lang planet neil/sicp
;;(square-list (list 1 2 3 4)) => (1 4 9 16)
(define a (list 1 2 3 4))
; define one
(define (square x)
(* x x))
(define (square-list items)
(if (null? items)
nil
(cons (square (car items)) (square-list (cdr items)))))
; define two
(define (square-list items)
(map (lambda (x) (* x x)) items))
运行:
Welcome to DrRacket, version 5.3.3 [3m].
Language: planet neil/sicp; memory limit: 512 MB.
> (square-list a)
(mcons 1 (mcons 4 (mcons 9 (mcons 16 '()))))
>