Erlang language summing up

1. The operator = (pattern matching)

When you see an expression like X = 123, it means seemingly "integer 123 to the variable X", but this interpretation is not

correct. = Not an assignment operator, it is actually a pattern matching operator. Like other functional programming languages, Erlang variables can only be bound once. Bind variables mean a value to a variable

2. Variable syntax and atoms

Please note Erlang variables to start with a capital letter. So X, This and A_long_name are variable. Lowercase letter

names beginning (such monday or Friday) is not variable, but constant symbols, they are called atoms (atom).

3. tuple

If you want some fixed number of items grouped into a single entity, it will use the tuple (tuple). Create a method tuple

It is intended to represent the value of braces enclose, and are separated by commas.

4. List

List (list) is used to store any number of things. The method is to create a list of list elements in square brackets to enclose,

And they are separated by commas.

The comma, semicolon, period

a comma (,) separated function call parameter data structure and mode.

Semicolon (;) delimited clauses. We can see the clause in many places, such as function definitions, and Case, IF,

a try..catch and receive expressions.

Full stop (.) (Followed by a blank) separating whole, as well as the shell of expression functions.

Is there an easy way to remember: Think English. Separated by periods sentences, clauses separated by semicolons, commas separated at the

level clause. Comma symbol of short-range, medium-range symbol semicolon, period, is a symbol of long-range.

 

6.fun: Abstract basic unit

Erlang is a functional programming language. In addition, functional programming languages ​​may also be used as a reference function represents the other functions

Number, can also return function. Function of the other operating functions are called higher-order function (higher-order function), while the Erlang

Data type used to represent the function is called fun.

 

7. Level

Level (Guard) is a structure that can be used to increase the power of pattern matching. By using checkpoints, some can

perform a simple test and compare mode in the variable. It supposes you want to write a letter calculating max (X, Y) between the X and Y maximum

number. Such levels can be used to prepare it as follows:

max (X-, the Y) When X-> the Y -> X-;

max (X-, the Y) -> the Y

Guess you like

Origin www.cnblogs.com/luluping/p/11972866.html