Construction of the program:
Abstract data abstraction, using function abstraction for the procedure that operates data (functions abstraction)
Abstraction barriers
Access certain properties of the data using the appropriate method, rather than starting with the data construction method
Sequence Processing:
- Sequence Iteration
- List comprehensions
- Aggregation:aggregate all values in a sequence to a single value. The built-in functions sum, Min, and Max is all examples of aggregation functions.
- Higher-order functions
Closure Property:a method for combining data values have a Closure property if the result of combination can itself be COM Bined using the same method. Closure is the key to power on any means of combination because it permits us to create hierarchical Structures-structur Es made up of parts, which themselves is made up of parts, and so on.
Dispatch Function:a General method for implementing a message passing interface for abstract data. The function is a dispatch function and its arguments be first a message, followed by additional arguments to Parameteriz E that method. This message was a string naming what's the function should do. Dispatch functions is effectively many functions in one:the message determines the behavior of the function, and the add Itional arguments is used in that behavior.
Generic function:a function that can accept values of multiple different types. We'll consider three different techniques for implementing generic functions
- Shared interfaces
- Type Dispatching:look up a cross-type implementation of an operation based on the types of its arguments
- Type Coercion:look up a function for converting one type to another and then apply a type-specific implementation.
Count how many times function calls
def count (f): def counted (*args): + = 1 return F (*args )= 0 return counted
Count how many frames is active
def Count_frames (f): def counted (*args): + = 1 = max (counted.max_count, Counted.open_count) = f (*args) -= 1 return result = 0 = 0 return counted
Memoization (using cache)
def Memo (f): = {} def memoized (n): if not in cache: = f (n) return cache[n] return memoized
Lexical Scope:
The parent of a frame is the environment in which a procedure was defined
Dynamic Scope:
The parent of a frame is the environment in which a procedure was called
Tail recursion
The general recursion takes the same time as the iteration, but it takes much more memory than the iteration
Tail recursion is the constant use of the frame to abandon
A non-tail context translates to tail context in PDF
(Recursion was the last thing in your procudure was tail context) #也给了我们什么时候用递归 when to use iterative convenience (all can be written as tail recursion by iteration)
2015-07-18
2. Building abstractions with Data