erlang book 零星摘要

Erlang has a process-based model of concurrency with asynchronous message passing.The concurrency mechanisms in Erlang are lightweight, i.e. processes require little memory, and creating and deleting processes and message passing require little computational effort.

Erlang has no shared memory. All interaction between processes is by asynchronous message passing.

Our goal was to produce a small, simple and ecient language suitable for programming robust large-scale concurrent industrial applications.

The use of a pattern matching syntax, and the `single assignment' property of Erlang variables, leads to clear, short and reliable programs.

The values of Erlang data types can be stored in variables. Variables always start with an upper-case letter.

The match primitive can be used to unpack items from complex data structures.

The special variable underscore (written `_') is the anonymous or don't care variable. It is used as a place holder where the syntax requires a variable, but the value of the variable is of no interest.

While we can think of send as sending a message and receive as receiving a
message, a more accurate description would be to say that send sends a message
to the mailbox of a process and that receive tries to remove a message from the
mailbox of the current process.

Atoms are constants with names;Atoms are used to enhance the legibility of programs.

Pattern matching provides the basic mechanism by which values become assigned
to variables.

Pattern matching occurs:
   when evaluating an expression of the form Lhs = Rhs
   when calling a function
   when matching a pattern in a case or receive primitive.


Many people think that the use of destructive assignment leads to unclear programs which are dicult to understand, and invites obscure errors.


The expression list(H) which comes between the keyword when and the `->' arrow is called a guard. The body of the function is evaluated if the patterns in the function head match and if the guard tests succeed.

Each function is built from a number of clauses. The clauses are separated by
semicolons `;'. Each individual clause consists of a clause head, an optional guard and a body.

A guard can be a simple test or a sequence of simple tests separated by commas.

Guards can be viewed as an extension of pattern
matching. User-de ned functions cannot be used in guards.

你可能感兴趣的:(erlang)