SICP-chapter2 Data Structure

Introduction to Data Structure

What is Meant by Data?

  • The definition of Data
  • 使用procedure实现cons,car以及cdr.
    • 使用条件语句实现这三个内置函数.
    • 其实可以让cons支持有限个参数(>2个),只需要在条件语句上多加几个情况.
  • Message Passing
    • definition: What is message passing?
  • Exercises 2.4
    1. Analyse the requirements
    • (car (cons x y))

      • (cons x y) 是作为参数传入car的,实际上会生成一个procedure m
      • (car z) 返回的也是一个procedure,这个返回的procedure的作用就是返回第一个参数。
      • 所以这整个函数的作用就是car,返回第一个参数。
    • 写一个cdr的procedure。

      • Section 1.1.5
        • substitution model
          1. (f 5), this f is the procedure (sum-of-squares )
          • When we are trying to evaluate f ,this f is replaced by procedure (sum-of-squares)
          • Why do we need to use the substitution model?
            • Because we need to verify whether cdr works
      • The idea is to implement a procedure take the second parameter out as the return.
      • We need the cdr procedure to do something as follows

        (cdr (cons x y)) returns y
        * So the arguments of cdr should be a procedure , and the return value should also be a concrete object rather than a procedure.
        >(define (cdr z) (z (lambda (x y) y))

  • How to implement the cons as a procedure?
    • (cons a b) -- (lambda (m) (m x y))
    • what is the return value of ‘cons'?
      • The return value is a kind of data structure. 'Data structure Object’
      • The return value can be manipulated by 'car' and 'cdr',
        • So the return value is a procedure.
          • What are the arguments of the procedure?
            """
            (define k (cons 4 5))
            (cdr k)
            (k (lambda (x y) y)
            (cons (4 5)) (lambda (x y) y)
            (lambda (m) (m 4 5)) (lambda ( x y) y)
            (lambda (x y) y) (4 5)
            5
            """

Conclution

  • We can implement cons car cdr by ourself
  • The cons returns a procedure which is the highest abstraction structure.
    • take procedure as arguments
    • returns object is also a procedure
  • We can make up our mind by implement the structure step by step.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 公元2015年7月11日晚,我在武汉万达影院汉街店仰望了国内顶尖的动漫佳作《西游记之大圣归来》。观看过后,感...
    书克兰阅读 4,827评论 5 30
  • 子规啼,杨柳舞,酒光映珠泪,醉中有离愁。 君泪盈,伊泪盈,杨柳折枝心未成,江中舟无影。
    絳畝阅读 187评论 2 0
  • 这不是成功学 这不是成功学 这不是成功学 稻盛和夫哲学的根基是敬天爱人和利他之心。 最近听到敬天爱人和利他之心比较...
    颖公子6阅读 210评论 0 0
  • 这一年,我好像去了很多很多地方,先是每年必去的普陀山,然后在无锡苏州去了常州恐龙园,后来特别幸福几大家一起自驾,从...
    汪飘飘阅读 276评论 0 0
  • 我以前做的swift笔记, 之前都是整理在onenote上, 最近想到整理出博客. 也方便自己查找, 可以当做自己...
    sunmumu1222阅读 163评论 0 0