2.17
(define (my-last-pair l)
(if (null? (cdr l))
(car l)
(last-pair (cdr l))))
(my-last-pair (list 23 72 149 34))
2.18
(define (my-reverse l)
(if (or (null? l) (= (length l) 1))
l
(append (my-reverse (cdr l)) (list (car l)))))
(my-reverse (list 23 72))
(my-reverse (list 23 72 149 34))
2.19
(define (no-more? coin-values)
(or (< (length coin-values) 0) (= (length coin-values) 0)))
(define (except-first-denomination coin-values)
(cdr coin-values))
(define (first-denomination coin-values)
(car coin-values))
(define (cc amount coin-values)
(cond ((= amount 0) 1)
((or (< amount 0) (no-more? coin-values)) 0)
(else
(+ (cc amount
(except-first-denomination coin-values))
(cc (- amount
(first-denomination coin-values))
coin-values)))))
(define us-coins (list 50 25 10 5 1))
(define uk-coins (list 100 50 20 10 5 2 1 0.5))
(cdr us-coins)
(car us-coins)
(cc 100 us-coins)
2.20
(define (odd-list l)
(cond ((or (null? l) (< (length l) 0) (= (length l) 0)) l)
((odd? (car l)) (append (list (car l)) (odd-list (cdr l))))
(else (odd-list (cdr l)))))
(define (even-list l)
(cond ((or (null? l) (< (length l) 0) (= (length l) 0)) l)
((even? (car l)) (append (list (car l)) (even-list (cdr l))))
(else (even-list (cdr l)))))
(odd-list (list 1 2 3 4 5 6 7))
(even-list (list 1 2 3 4 5 6 7))
(define same-parity (lambda (n . l)
(if (odd? n)
(append (list n) (odd-list l))
(append (list n) (even-list l)))))
(same-parity (list 1 2 3 4 5 6 7))
分享到:
相关推荐
《计算机程序的构造和解释》...通过解答SICP的习题,读者将深入理解这些概念,并能运用到实际的编程实践中。习题旨在促进对这些基本原理的深入思考,帮助程序员建立坚实的基础,进而在面对复杂的编程挑战时能游刃有余。
以上就是基于文件名推测的SICP第二章练习题相关知识点。这些内容深入地涵盖了函数式编程的基础和应用,对于提升编程思维和技能大有裨益。实际的学习过程中,通过阅读和理解这些代码,结合原书的理论部分,将有助于...
《SICP习题解答,主要第一章的内容习题答案》 SICP,全称《Structure and Interpretation of Computer Programs》(计算机程序的构造和解释),是计算机科学领域的一本经典教材,由MIT(麻省理工学院)的 Harold ...
SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版
在" sicp-master "这个压缩包中,可能包含的是对SICP各章节练习题的解答,包括源代码、注释和分析。这些练习通常涵盖了函数式编程的基础,如高阶函数、递归、闭包,以及更高级的主题,如过程构造、数据结构、环境...
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download>>>https://github.com/wizardforcel/sicp-py-zh
《SICP解题集》是一份专注于探讨和解答《结构与解释程序》(Structure and Interpretation of Computer Programs,简称SICP)一书中习题的资源。SICP是计算机科学领域的一本经典教材,由Harold Abelson、Gerald Jay ...
"sicp-solutions"是一个针对该书练习题的解答集,主要使用了Scheme语言,一个Lisp方言,而具体的实现环境是mit-scheme 9.2。 Scheme语言是Lisp家族的一员,以其简洁的语法和强大的函数式编程特性闻名。在"sicp-...
《计算机程序的构造与解释》(Structure and Interpretation of Computer Programs,简称SICP)是一本备受推崇的经典计算机科学教材,由Harold Abelson和Gerald Jay Sussman撰写,并由MIT出版社出版。这本书以其深入...
scheme编译器最新版,Windows下直接安装即可运行,sicp刷题必备。祝大家早日学到sicp之精髓~
《SICP 2.2.4 节:图形语言》是计算机科学经典教材《结构与解释程序》(Structure and Interpretation of Computer Programs)中的一个重要章节,它深入介绍了如何利用编程来创建图形,以及如何设计和理解复杂的计算...
《计算机程序构造和解释》(SICP,Structure and Interpretation of Computer Programs)是一本具有深远影响力的计算机...压缩包中的“SICP 北大课件”文件可能包含课件、讲义、习题解答等资料,是学习SICP的宝贵资源。
SICP-Python版本
SICP 使用的scheme解释器 以前叫DrScheme
Python SICP epub版本,很适合学习抽象的思想,用Python版本比lisp更实用
《SICP》全称是《Structure and Interpretation of Computer Programs》,中文译为《计算机程序的构造和解释》。这是一本经典的计算机科学教材,由Harvard大学的 Harold Abelson 和 Gerald Jay Sussman 教授撰写,...
标题中的"PyPI 官网下载 | sicp-0.0.1b102.dev4.tar.gz"指的是从Python的官方包索引(Python Package Index,简称PyPI)上下载的一个名为"sicp"的软件包的版本号为0.0.1b102.dev4的压缩文件,其格式是tar.gz。...
本书名为《a_book_sicp_py》,是一本以Python语言为基础介绍设计模式和计算机科学基础的书籍。根据描述和部分内容,可以提炼出以下知识点: 1. 编程语言的重要性:在计算机科学的宽泛领域中,编程语言扮演着至关...
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 download : https://github.com/wizardforcel/sicp-py-zh