Transcription of the construction and interpretation of computer programs (1): Construction process Abstraction

Source: Internet
Author: User

is Q:SICP about software engineering?
A: part, but not all. Mainly is the modularization and the black box abstraction, two main basic ideas in the computer. SICP is concerned with: "When the complexity of the system explodes (or before), how can we control the complexity of the system through effective methods and means?" ”
  
Q:SICP, is it about compiling principles?
A: In part, and, as the title says, "compilation" in SICP is "interpretation", and the behavior of this interpretation is to simulate another machine with the computational behavior of one machine.

A computer language is not just a way for a computer to perform operations, but rather a novel formal medium for expressing ideas about methodology. The most basic material is not a language-specific grammar, not a clever algorithm for efficient computation, not the essential basis for the mathematical analysis of the algorithm to live computing, but some technology that can control the intelligence complexity of large-scale software systems.
The computational process is a class of abstract things that exist in the computer, and in the course of its evolution, these processes manipulate some abstract things that become data.
A good programming language is not just about directing computers to accomplish tasks. It is also a framework through which we think about the process of achieving task calculation.

Discovering and mastering strong organizational skills will enhance our ability to construct large, important programs.

The mind's activities, in addition to creating a simple understanding, there are three aspects:
1) combine simple realizations into complex understandings
2) to compare different understandings and get the understanding of their mutual relations
3) Isolate common knowledge from other understandings, so-called "abstraction"
The general situation is the individual, the whole, the relationship, the abstract, like the things in the horse Zhe ha ~

basic elements of program design:
When we describe a language, pay particular attention to what this language provides, and the way in which a complex understanding can be formed by combining a simple understanding. Each of these powerful languages provides three mechanisms for this:
1. Basic form of expression: used to denote the simplest individual to which the language is concerned.
2. The way of composition: through which they can construct complex elements from simple elements.
3. Abstract methods: They can be used to name the composite element and act as a unit.

Data is an action object, and a procedure is a description of the rules about how to manipulate it. In this way, any powerful programming language must be able to articulate basic data and basic processes, as well as to provide methods for combining and abstracting processes and data.

Naming and Environment
The programming language must provide a mechanism for naming objects, which is the most basic abstraction mechanism.
In scheme, there are:

(define pi 3.14159)(define radius 10)(define circumference (* 2 pi radius)

The define above is one of the simplest abstractions that help us to correlate values with numbers, meaning that the interpreter must have some kind of storage capability, store this association, and "Environment".

The structure of the computed object can be complex, requires complex time-consuming computations to be obtained, and, if recalculated on a per-use basis, can be costly and laborious, and can be used more easily by naming computed results.

Combined Evaluation:
1) The combination of the various sub-values (recursion, processing hierarchical structure of powerful tools)
2) evaluation by calculation and calculation object

  

Composite Process:
1) Number and arithmetic operations are basic data and processes.
2) A combination of nesting provides a way to combine multiple operations.
3) definition is a restricted abstraction that associates a corresponding value for a name

A process definition is a more powerful technique that can provide a name for a composite operation, which can then be used as a unit.

For example, we consider defining the square "a number squared that is itself multiplied by itself", namely:

(define (square x) (* x x))

OK, now we have a compound process whose name is square (definition).
Once we've defined square, we can use it as a unit:

(square 10)100(square (+ 2 5))49

We can do it. Square as a basic component to construct other operations, such as X^2+Y^2, can be described as:

(+ (square x) (square y))

We define this operation as Sum_of_square:

(define (sum_of _square x y) (+ (square x) (square y)))

OK, we can use this unit to construct more complex operations, such as:

(define (f a) (sum_of _square (* a 2) (+ a 1)))

Complex procedure is usually to calculate (construct) a very difficult to get the object, through multi-step construction and naming, decomposition of the construction process, making it easier to carry out, the establishment of the name-Object Association is one of the most important abstract means.
Process definition is one of the most important techniques for decomposition and control program complexity.
It is the charm of compounding that is complicated by simplicity.

substitution models for process applications:
The computational process determined by the combined and composite process is (substitution model):
1) Find the values of each parameter expression (sub-expression)
2) Find the definition of the procedure to invoke (based on the evaluation result of the first subexpression)
3) The formal parameters in the body of the substitution process of the actual parameters obtained
4) Evaluation Process body

Cases:

(f 5)  using the original process body (Sum-of-squares (+ a 1) (* a 2)), the substitution is obtained by:(sum-of-squares (+ 5 1) (* 5 2 ))  ; Evaluates an argument and takes it into the process body to get:(+ (square 6) (square ))  ; Evaluates an argument and takes it into the process body to get:(+ (* 6 6) (* ten )) (+ +  ) 136

It can be seen that the above is a process of constant normalization, which is called the substitution model of process application.
The substitution model is only to help the intuitive understanding of the behavior of the process application, it does not reflect the actual work of the interpreter, the actual interpreter based on the local environment implementation.

application and regular order evaluation:
As in the example above, the interpreter evaluates the subexpression (operator and each operand) and then applies the resulting operation to the operand (the actual parameter), which is called the application Order evaluation, which is actually used in the interpreter.
Of course it's easy to think of another way of fully unfolding, then the normalization is called the regular order evaluation, for example:

(sum-of-squares (+ 5 1) (* 5 2) )(+ (square (+ 5 1)) (  Square (* 5 2) ))(+ (* (+ 5 1) (+ 5 1 )) ( * ( * 5 2) (*  5 2 )))first unfold, back to about(+ (* 6 6) (* ten ))(+ +  )136

Obviously, the application avoids some repetition and is more efficient, which is probably the reason why the interpreter chooses this way of implementation.

Of course, you can also write a program to test whether the interpreter is an application or a regular order:

(define (p) (p))(define (test x y)      (if (= x 0)      0      y))(test 0 (p))

The application will obviously have a wireless loop, and the regular order will return 0.

conditional Expressions and predicates:
So far, our definition process has been very limited in terms of expression, such as we have not been able to conduct conditional detection, and the description of complex calculations always need to describe conditions and choices, such as the absolute value.
Let's look at the following form of conditional expression:
Each p (condition) is evaluated in turn, and the value corresponding to the first condition that is not false is evaluated with its value as the entire cond expression.

(cond (<p1> <e1>) ; (<p2> <e2>) …(<pn> <en>))

Expressions such as PN (to find a true or false value) are called predicates.

It can be written in scheme:

 (define   (abs  x)   (cond    (>  x 0 )  x)   ( (=   x 0 )   0 )  <   x 0 )   (-  x) ) ) )   

In addition to predicates such as >=<, various relational operators are basic predicates, such as And,or,not
(And ...) Evaluates e one at a-until an e is calculated, or the last e-evaluation is completed. The value of the sub-expression with the last evaluation as the value
(Or ...) Evaluates e one at a-until an e-evaluates the true, or the final e-evaluates to completion. The value of the sub-expression with the last evaluation as the value
(not) If the value of E is not true, it must be true, or it will be false.

Complex logic conditions can be combined with and, or, not, and you can define predicates using procedures, such as conditions that are greater than 5 and less than 10:

(define (num_5_10 x) (and (>5) (<10)))

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Transcription of the construction and interpretation of computer programs (1): Construction process Abstraction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.