sicp笔记--①

来源:互联网 发布:淘宝网卖家注册流程 编辑:程序博客网 时间:2024/06/06 14:05
learning note -- start

Mathematics provides a framework for dealing precisely with notions of ``what is.''
Computation provides a framework for dealing precisely with notions of ``how to.'' 
数学提供一个框架处理"什么是"
计算机科学处理"怎么做"


when we describe a language, we should pay particular attention to the means that the language provides for combining simple ideas to form more complex ideas.Every powerful language has three mechanisms for accomplishing this: 

primitive expressions, which represent the simplest entities the language is concerned with,
means of combination, by which compound elements are built from simpler ones, and
means of abstraction, by which compound elements can be named and manipulated as units. 

一个共鞥能强大的语言必须拥有的三种性质
描述简单实体的表达式
将简单元素结合到一起的方法
将结合的元素命名并像单元一样处理


The convention of placing the operator to the left of the operands is known as prefix notation
advantages:
①it can accommodate procedures that may take an arbitrary number of arguments
②prefix notation is that it extends in a straightforward way to allow combinations to be nested, that is, to have combinations whose elements are themselves combinations

前缀表达式的优点:
①可以提供任意数量的参数
②可以以简单的方式被嵌套,即可以用自身组装自身


the interpreter must maintain some sort of memory that keeps track of the name-object
pairs. This memory is called the environment (more precisely the global environment, since we will
see later that a computation may involve a number of different environments)
解析器需要维持一定的内存来保证对象和名称的对应。这部分内存就叫环境

 In general, we shall see that recursion is a very powerful technique for dealing with hierarchical, treelike objects. In fact, the ``percolate values upward'' form of the evaluation rule is an example of a general kind of process known as tree accumulation
递归是处理分层或树状对象的非常强力的技术。

The general form of a procedure definition is
(define (<name> <formal parameters>) <body>)
过程的定义

``fully expand and then reduce'' evaluation method is known as normal-order evaluation, in contrast to the ``evaluate the arguments and then apply'' method that the interpreter actually uses, which is called applicative-order evaluation.
全部扩展再处理的方法叫做正常序求值,与此相对,求参数值然后应用之的方法,是解析器常用的方法,这叫做叫应用序求值

(cond (<p1> <e1>)
      (<p2> <e2>)
      ...
      (<pn> <en>))


Lexical scoping dictates that free variables in a procedure are taken to refer to bindings made by
enclosing procedure definitions; that is, they are looked up in the environment in which the
procedure was defined.
词法定界 词法作用域
把外层参数的值记录在内层函数的闭包里的做法,叫做“lexical scoping”或者“static scoping”


This type of process, characterized by a chain of deferred operations, is called a recursive process.
linear recursive process
一连串的延迟调用链叫做递归计算过程

iterative process. In general, an iterative process is one whose state can be summarized
by a fixed number of state variables, together with a fixed rule that describes how the state
variables should be updated as the process moves from state to state and an (optional) end test that
specifies conditions under which the process should terminate.

linear iterative process

In contrasting iteration and recursion, we must be careful not to confuse the notion of a recursive
process with the notion of a recursive procedure. When we describe a procedure as recursive, we
are referring to the syntactic fact that the procedure definition refers (either directly or indirectly) to the procedure itself. But when we describe a process as following a pattern that is, say, linearly
recursive, we are speaking about how the process evolves, not about the syntax of how a procedure
is written. It may seem disturbing that we refer to a recursive procedure such as fact-iter as
generating an iterative process. However, the process really is iterative: Its state is captured
completely by its three state variables, and an interpreter need keep track of only three variables in
order to execute the process.
迭代和递归形成鲜明的对比,我们要注意,递归的过程说明的是在句法上是递归的,而计算过程可能是迭代的,即一个递归的过程可能有一个迭代的计算过程。

One reason that the distinction between process and procedure may be confusing is that most
implementations of common languages (including Ada, Pascal, and C) are designed in such a way
that the interpretation of any recursive procedure consumes an amount of memory that grows with
the number of procedure calls, even when the process described is, in principle, iterative. As a
consequence, these languages can describe iterative processes only by resorting to special-purpose
``looping constructs'' such as do, repeat, until, for, and while. The implementation of
Scheme we shall consider in chapter 5 does not share this defect. It will execute an iterative process
in constant space, even if the iterative process is described by a recursive procedure. An
implementation with this property is called tail-recursive. With a tail-recursive implementation,
iteration can be expressed using the ordinary procedure call mechanism, so that special iteration
constructs are useful only as syntactic sugar.

迭代是递归的一种特殊形式,在其他语言中,使用until,for,while等等关键字描述,而在scheme等一些函数式语言中,递归会自动以迭代的方式实现,这种特性叫做尾递归。







原创粉丝点击