From expression to variable: what you see in a row of scheme code

Source: Internet
Author: User

The following line of code can be executed in scheme, and the result value is 12:
-----------
(If # F + *) 3 4)
-----------

In scheme, a pair of parentheses indicates a process call. The first parameter in the brackets is the process name, And the rest
Is a process parameter.

First, let's look at the code in the inner brackets:
-----------
(If # F + *)
-----------

"If" is a process name, not a statement. This process is equivalent to a three-element table in Javascript or C.
Or an if Statement (effect) in other languages ). Describe it in Javascript
Effect (the string definition in the following statement is only a semantic meaning and does not indicate that it is a character.
String ):
-----------
VaR q = '# F ';
VaR V1 = '+ ';
VaR v2 = '*';

(Q? V1: V2 );
-----------

Or use Pascal to describe its effect:
-----------
Function _ if (B: Boolean; V1, V2: tsymbol): tsymbol;
Begin
If (B) then
Return V1
Else
Return V2;
End;

VaR
Q: Boolean = false;
V1: tsymbol = '+ ';
V2: tsymbol = '*';

_ If (Q, V1, V2 );
-----------

In the preceding example, both + and * can only be recorded as characters because both JavaScript and Pascal
Operators are interpreted as syntax symbols, while scheme interprets them as procedure ). However
Process is a piece of code, so there is a storage address. A storage address can be understood as a variable.

In other words, operators in scheme are "variables" that can be understood by program code ". Common advanced languages
Operators are understood by the interpreter or compiler.

() In scheme indicates the execution of a process (or a function in the general sense ). Since operators are interpreted
Built-in process, statement predicates can also be understood as built-in process ...... In general, our understanding of language is:
Operators, expressions, statements, and variables (and constants ). Therefore, an important conclusion is:
-All syntax elements can be understood as "process calls ".

So
-----------
(If # F + *)
-----------
The effect of this code snippet is expressed as a call to a built-in process in scheme.
Some of its languages must be expressed using ternary expressions, statements, and function calls. -- What's more, they
Operators cannot be considered as variables ".

In the above Code, the call of the inner layer returns an operator (# F is the value of false, so * is returned). Therefore
The outer code is changed:
-----------
(* 3 4)
-----------
In this way, the process * is called, that is, multiplication. The result is 3*4 = 12.

In the code analysis above, we have seen some fundamental things of "functional language:
-The statement can be understood as the effect of a process (function) Call;
-Operators can also be understood as the effects of process (function) calls;
-Since operators and statements (predicates) can be understood as processes, they can be understood
Address.

Because all semantic elements of a language can be understood as variables (or data storage addresses) and
Can be understood as the operation effect of the "()" symbol (process call. Therefore, scheme uses
The concepts "operations" and "variables" completely summarize all the code. Its code has only one meaning:
-----------
(Symbol)
-----------

Finally, let's talk a little bit: We call scheme a functional language, and the class belongs to the points of a "declarative" language.
Class. The explanatory language is oriented to the explanation of the "Algorithm" in "program = Algorithm + structure. What we commonly use
Object-oriented and process-oriented High-level language, the class is a "imperative" language, focusing on
Structure.

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.