計算機プログラムの構造と解釈 第二版 P60 問題2.21
マー楽勝っす。
<??>ってなってるところを埋める問題。
はい実装
#!/usr/local/bin/gosh ;; -*- coding: utf-8 -*- (use ggc.debug.trace) (use math.mt-random) (define nil '()) (define (square-list items) (if (null? items) nil (cons (* (car items) (car items)) (square-list (cdr items))))) (define (square-list-map items) (map (lambda (x) (* x x)) items)) ;; main (define (main args) (display "(square-list (list 1 2 3 4))): ") (display (square-list (list 1 2 3 4))) (newline) (display "(square-list-map (list 1 2 3 4))): ") (display (square-list-map (list 1 2 3 4))) (newline) 0)
実行
(square-list (list 1 2 3 4))): (1 4 9 16) (square-list-map (list 1 2 3 4))): (1 4 9 16)
こんな感じで。