The Little Schemer读书笔记1

到第32页(第四版 电子工业出版社)

1、书中定义的函数

1)检查是否为原子:

(define atom?
  (
   lambda(x)
    (and (not (pair? x)) (not (null? x)))))
2)检查列表元素是否全部为原子:

(define lat?
  (lambda(l)
    (cond
      ((null? l)#t)
      ((atom? (car l))(lat? (cdr l)))
      (else #f))))

3)检查原子是不是列表的成员:

(define member?
  (lambda(a lat)
    (cond
      ((null? lat)#f)
      (else(or(eq? (car lat)a)
              (member? a(cdr lat)))))))

2、一些内建的方法:

1)car:取得点对的第一个元素

2)cdr:取得点对的第二个元素

3)cons:构造点对

4)null?:判断列表是否为空,是则返回#t

5)eq?:判断两元素是否相等,是则返回#t

注意:car返回的是列表中的第一个原子,而cdr总会得到一个(除去了第一个原子的)列表,在书里有一个例子:

(eq?(cdr l)a)是真是假,其中l是(soured milk),a是milk。答案是没有答案,原因是(cdr l)得到的是(milk),是一个列表,而另一个比较对象是原子。然而在racket里。。。。



The Reasoned Schemer (MIT Press) (The MIT Press) By 作者: Daniel P Friedman – William E Byrd – Oleg Kiselyov – Jason Hemann ISBN-10 书号: 0262535513 ISBN-13 书号: 9780262535519 Edition 版本: second edition 出版日期: 2018-03-09 pages 页数: (206) A new edition of a book, written in a humorous question-and-answer style, that shows how to implement and use an elegant little programming language for logic programming. The goal of this book is to show the beauty and elegance of relational programming, which captures the essence of logic programming. The book shows how to implement a relational programming language in Scheme, or in any other functional language, and demonstrates the remarkable flexibility of the resulting relational programs. As in the first edition, the pedagogical method is a series of questions and answers, which proceed with the characteristic humor that marked The Little Schemer and The Seasoned Schemer. Familiarity with a functional language or with the first five chapters of The Little Schemer is assumed. For this second edition, the authors have greatly simplified the programming language used in the book, as well as the implementation of the language. In addition to revising the text extensively, and simplifying and revising the “Laws” and “Commandments,” they have added explicit “Translation” rules to ease translation of Scheme functions into relations. Copyright Contents Foreword Preface Acknowledgements Since the First Edition 1.Playthings 2.Teaching 01d Toys New Tricks 3.Seeing 01d Friends in New Ways 4.Double Your Fun 5.Members Ornly 6.The Fun Never Ends… 7.A Bit Too Much 8.Just a Bit More 9.Thin Ice 10.Under the Hood A.Connecting the Wires B.Welcome to the Club Afterword Index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值