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

本章探讨了如何使用数据建立抽象,包括复合数据对象、数据抽象的关键点(如封闭性和传统接口)。介绍了选择器和构造器的概念,通过理数运算、对偶和闭合属性展示了数据抽象。此外,还讨论了层次数据、序列作为常规接口以及符号数据的应用,如数据定向编程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值