您的位置:首页 > 产品设计 > UI/UE

《SICP》读书笔记--Chapter 2 Building Abstraction with Data

2015-09-30 17:14 621 查看
Chapter 2 Building Abstraction with Data

compound data object

data abstraction: isolating the parts of a program that deal with how data objects are used

key points: closure, conventional interface

2.1 Introduction to Data Abstraction

Procedure Abstraction: separate the way the procedure would be used from the details of how the procedure would be implemented in terms of more primitive procedures.

Data Abstraction: isolate how a compound data object is used from the details of how it is constructed from more primitive data objects.

Selectors / Constructors

2.1.1 Arithmetic Operations for Rational Numbers

Pairs

cons car cdr

2.1.2 Abstraction Barriers

--- Programs that use rational numbers ---

   Rational numbers in problem domain

--- add-rat, sub-rat ... ---

   Rational numbers as numerators and denominators

--- make-rat numer demom ---

   Rational numbers as pairs

--- cons car cdr ---

2.1.3 What Is Meant by Data?

Data: defined by some collection of selectors and constructors, together with specified conditions that these procedures must fulfill in order to be a valid representation.

example: 

x = make-rat(n, d)

(number x)/(denom x) = n/d

Procedural presentation of data play a central role in our programming repertoire. This style of programming is often called message passing.

2.1.4 Extended Exercise: Interval Arithmetic

2.2 Hierarchical Data and the Closure Property

Closure Property of cons: an operation for combining data objects satisfies the closure property if the results of combining things with that operation can themselves be combined using the same operation.

2.2.1 Representing Sequences

2.2.2 Hierarchical Structures

2.2.3 Sequences as Conventional Interfaces

Modular construction is a powerful strategy for controlling complexity in engineering design

enumerate / filter / map / accumulate

2.2.4 Example: An picture language

2.3 Symbolic Data

... ... 

2.4.3 Data-Directed Programming and Additivity

dispatch on type: check the type of a datum and calling an appropriate procedure. problem: must know about all the different representations.

data-directed programming
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  SICP abstraction