;; 2.30
;(define (square-tree tree)
; (cond ((null? tree) nil)
; ((not (pair? tree)) (* tree tree))
; (else (cons (square-tree (car tree))
; (square-tree (cdr tree))))))
;(define (square-tree tree)
; (map (lambda (sub-tree)
; (if (pair? sub-tree)
; (square-tree sub-tree)
; (* sub-tree sub-tree)))
; tree))
;; 2.31
(define (square x) (* x x))
(define (tree-map proc tree)
(cond ((null? tree) nil)
((not (pair? tree)) (proc tree))
(else (cons (tree-map proc (car tree))
(tree-map proc (cdr tree))))))
(define (square-tree tree) (tree-map square tree))
;(square-tree
; (list 1
; (list 2 (list 3 4) 5)
; (list 6 7)))
;; 2.32
(define (subsets s)
(if (null? s)
(list nil)
(let ((rest (subsets (cdr s))))
(append rest (map (lambda (x) (cons (car s) x)) rest)))))
;(subsets (list 1 2 3))
分享到:
相关推荐
《计算机程序的构造和解释》...通过解答SICP的习题,读者将深入理解这些概念,并能运用到实际的编程实践中。习题旨在促进对这些基本原理的深入思考,帮助程序员建立坚实的基础,进而在面对复杂的编程挑战时能游刃有余。
以上就是基于文件名推测的SICP第二章练习题相关知识点。这些内容深入地涵盖了函数式编程的基础和应用,对于提升编程思维和技能大有裨益。实际的学习过程中,通过阅读和理解这些代码,结合原书的理论部分,将有助于...
《SICP习题解答,主要第一章的内容习题答案》 SICP,全称《Structure and Interpretation of Computer Programs》(计算机程序的构造和解释),是计算机科学领域的一本经典教材,由MIT(麻省理工学院)的 Harold ...
What I have stored is the reading notes of SICP and the solutions of the exercises after class.:art:SICP()
SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版
《SICP解题集》是一份专注于探讨和解答《结构与解释程序》(Structure and Interpretation of Computer Programs,简称SICP)一书中习题的资源。SICP是计算机科学领域的一本经典教材,由Harold Abelson、Gerald Jay ...
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download>>>https://github.com/wizardforcel/sicp-py-zh
在" sicp-master "这个压缩包中,可能包含的是对SICP各章节练习题的解答,包括源代码、注释和分析。这些练习通常涵盖了函数式编程的基础,如高阶函数、递归、闭包,以及更高级的主题,如过程构造、数据结构、环境...
《计算机程序的构造与解释》(Structure and Interpretation of Computer Programs,简称SICP)是一本备受推崇的经典计算机科学教材,由Harold Abelson和Gerald Jay Sussman撰写,并由MIT出版社出版。这本书以其深入...
《SICP 2.2.4 节:图形语言》是计算机科学经典教材《结构与解释程序》(Structure and Interpretation of Computer Programs)中的一个重要章节,它深入介绍了如何利用编程来创建图形,以及如何设计和理解复杂的计算...
《计算机程序构造和解释》(SICP,Structure and Interpretation of Computer Programs)是一本具有深远影响力的计算机...压缩包中的“SICP 北大课件”文件可能包含课件、讲义、习题解答等资料,是学习SICP的宝贵资源。
SICP-Python版本
SICP 使用的scheme解释器 以前叫DrScheme