Positioning SICP 2: Building Abstractions with Data
作者:何岩,recreating.org出品,谢绝转载。
阅读SICP,站在Lisp发明者的上帝视角来思考:“我为什么要这么设计Lisp?”
0.前言:Why I design the concept of Data? 为什么要设计Data这个概念?Procedure不够用吗?
因为,control complexity。
因为,人脑习惯Object View,需要让人们产生Data这个Object想象体。这样可以降低思考复杂度。
因为,Object/Data的抽象思想是Black-Box Abstraction,也可以称为modularity。modularity可以降低复杂度,因为,modularity减少了关系发生的数量。
因为,统一视角,抽象思维,type的本质。例如:Java中的接口
Procedure is Stream View
Data is Object View
1.How I design the implementation of Data?我如何设计Data的实现?
— Chapter 2.1.3 What Is Meant by Data?
我将用Procedures来虚拟出Data。
Data对外提供可以被感知到的是一层interface,interface的本质就是procedure。
用户就会想象,Data貌似真的存在。
其实,那些作为interface的procedure也是由更底层的procedure组成的。
例如,用procedure来模拟Pairs的存在
为了欺骗使用Pair的人,我会提供Cons/Car/Cdr这三个Procedures作为interface。
使用Pair的人会这么操纵Pair暴露的interface:cons/car/cdr:
=>(define x (cons 1 2) ;构建一个叫做x的Pair,由1和2组成
=>(car x) ;获得Pair中存储的第一个元素
1
=>(cdr x) ;获得Pair中存储的第二个元素
2
我们来看看这三个Procedures的内部究竟有没有Data...