Erlang features-Summary

Source: Internet
Author: User

Summary: The features of Erlang are almost different from those of Erlang...

Variable immutable:

Guarantees atomicity and prepares for parallelism.

Tuples:

Similar to the structure in C language.

Person = {person,      {name,joe},      {height,1.82}.  }.

List:

[H | T]. The list starts with H and ends with T. The vertical line symbol (|) can separate the header and tail of the list, while [] is an empty list.

ThingsToBuy = [{apples,10},{pears,6},{milk,3}].

Pattern Matching:

= Indicates a pattern matching operation. LHS = RHS is actually such a process, evaluate the right end (RHs), and then match the result with the left end (LHS) pattern.

38 P.

Recursion:

General Syntax:

total([Head|Tail]) ->some_function_of(Head) + total(Tail);total([]) ->    0.

Example:

-module(mylists).-export([sum/1]).sum([H|T]) -> H + sum(T);sum([])    -> 0.       

Process:

Sum ([1, 3, 10]) = 1 + sum (3, 10)

= 1 + 3 + sum ([10])

= 1 + 3 + 10 + sum ([])

= 1 + 3 + 10 + 0

= 14

List parsing:

 
(Erlang-my@thomescai-G41MT-S2)4> L = [1,2,3,4].[1,2,3,4](Erlang-my@thomescai-G41MT-S2)5> [2*X || X <- L].[2,4,6,8]

[F (x) | x <-L] indicates a list composed of f (x), where X is set to list L. Therefore, [2 * x | x <-L] means "List of each element x in list l multiplied by 2".

Arithmetic expression:

P57.

Assertion example:

The assertion sequence can be a single assertion or a series of assertion sets separated by semicolons. In the assertion set G1; G2 ;...; In gn, As long as any asserted is true, the entire asserted sequence is true.

F (x, y) When is_integer (x), x> Y, Y <6->...

Record:

Records are tuples.

Eshell V5.8.3  (abort with ^G)1> rr("records.hrl").[todo]2> X=#todo{}.#todo{status = reminder,who = joe,text = undefined}3> X1 = # todo{status=urgent,text="Fix errata in book"}.#todo{status = urgent,who = joe,text = "Fix errata in book"}4> X2 = X1#todo{status=done}.#todo{status = done,who = joe,text = "Fix errata in book"}

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.