[Erlang 0011] Erlang Note II

Source: Internet
Author: User

When I learned Erlang, I recorded some items in the white space of the book, and some of them were recorded in the demo notes. Today I 've sorted out some of them and shared them.

Last address: [Erlang 0009] Erlang note

  1. Erlang is a message-oriented language. The message-oriented language does not share objects. inter-process interaction is completed by sending and receiving messages.
  2. An assigned variable in Erlang is a pointer pointing to the storage area of the stored value.
  3. A single value assignment means that the value of the bucket will not be modified.
  4. If Erlang does not share memory, there will be no locks.
  5. The order in which function clauses are matched is the order in the file.
  6. The data generator part of list parsing can also achieve data filtering through pattern matching [x | {A, x} <-[{A, 1}, {B, 12}, {C, 33}, {A, 23}].
  7. The reverse/1 of the lists module is highly optimized and can be used to rearrange the order of lists elements.
    Note:Instead of writing your ownreverse/1Function, you shocould uselists:reverse/1. It's been used so much for tail recursive callthat the maintainers and developers of Erlang decided to turn it into a BIF. your lists can now benefit from extremely fast reversal (thanks to functions written in C) which will make the reversal disadvantage a lot less obvious.
  8. All BIF is in the Erlang module, so don't be surprised that the functions contained in this module are so complicated.
  9. The binary data composed of character sequences is equivalent to the binary data consisting of each ASCII Code <"King">
    ==< <$ K, $ I, $ N, $ G>
  10. The integers used in binary data must be between 0 and 255, because each byte in binary data is 8 bits, 2 #11111111
  11. <A >>=< <255>. <B> = <256>. <C >>=< <257>. the values of a B C are respectively 255 0 1

  12. Bit syntax end-sign-type-Unit: a data example:
    8/unsigned-little-integer
  13. Apply (M, F, A) is 6 ~ slower than calling the corresponding method M: F (A1, a2 ~ 10 times, try to avoid using
  14. Check that metadata of a module can be used
    Modlue: module_info (). During module compilation, module_info is automatically created.
  15. Beam_lib: The chunk/2 method can analyze beam metadata without loading code.
  16. Begin end
    Block expressions remind me of the VB syntax, which is rarely used. Where multiple expressions need to be written, they are basically extracted as independent methods.
  17. F1 = fun (x) when x = 0-> X; (x)
    -> X + 100 end. % note that guard can be used here.
  18. Step_two (n, total) WHEN n =/= 0
    -> Step_two (N-1, total + n). % note that guard is also used
  19. EPP Erlang pre-processor I mentioned before when talking about macros and record
    Link: http://www.cnblogs.com/me-sa/archive/2011/07/20/erlang0006.html
  20. The process dictionary is suitable for storing global read-only configurations.
  21. Erlang: make_ref
    Create a unique identifier, which is commonly used in gen_tcp
  22. Q () is the alias of init: Stop () Erlang: Halt ()
    Both methods can disable the Erlang system.
  23. The ERL parameter-s can be executed multiple times in sequence.
    -The noshell parameter allows the program to run in the background.
  24. Code: clash () method in code
    Find the module with duplicate names in Path
  25. Press Ctrl + G in shell to enter "shell jcl" job
    Control language is commonly used by j c r commands.
  26. Execute help () in Shell ()
    Many practical auxiliary methods
  27. The execution of the spawn (fun) method will not fail, and a PID will always be returned
  28. Erlang: system_info/1 can obtain the system information at runtime, such as the number of process atoms.
    Memory consumption, etc.
  29. The 0-Timeout Statement of receive can help us quickly clear the mail queue
  30. The process that captures the Exit message is called the system process
    Process), learning new things is often based on the threshold brought by terms.
  31. Used exit (PID, kill) to clean up botnets when handling problems online.
  32. -Sname can be used only when no DNS service is required
  33. To enable the Erlang node to communicate with different hosts, You need to enable the TCP and UDP4369Port, EMPD (Erlang
    Port mapper daemon) will use this port
  34. To use distributed Erlang, you need to open some ports or specify the port range, and ensure that the firewall has been opened.
    Use-kernel inet_dist_listen_min for startup parameters
  35. File: Consult can directly read the Erlang items in the file.
    File: unconsult can write Erlang items to files.
  36. IO: Format ("123 ~ W ~ N ", [" ABC "]). Output: 123 [97,98, 99] ~ W write data with standard syntax
  37. IO: Format ("123 ~ P ~ N ", [" ABC "]). Output: 123" ABC "~ P complete print Parameters
  38. Group_leader () is used to manage the output. For example, the RPC call intercepts the result output from the target machine and outputs it to the current shell.
  39. A compacting Garbage Collector for Erlang (1997) http://citeseerx.ist.psu.edu/viewdoc/summary? Doi = 10.1.1.34.2421
  40. % Unified Call interface capture exception execution M f a init_p_do_apply (M, F, A)-> tryapply (M, F, a) catchclass: reason-> exit_p (class, reason) end.
  41. % Search for process PID by Registration Name
    Name_to_pid (name)->
    Case whereis (name)
    Undefined->
    Case Global: safe_whereis_name (name)
    Undefined->
    Exit (could_not_find_registerd_name );
    PID->
    PID
    End;
    PID->
    PID
    End.
  42. Erlang: get_stacktrace ().Normally, the execution stack trace isn't stored in the part of the exception that you can see; it's stored internally. you can inspect the stack trace of the latest thrown exception of the current process by calling the built-in function Erlang: get_stacktrace ().
  43. % Check whether the process is alive is_process_alive (PID) When is_pid (PID)-> RPC: Call (node (PID), Erlang, is_process_alive, [pid]).
  44. Erlang: system_info (min_heap_size ).
    {Min_heap_size, 233}
    Erlang: system_info (min_bin_vheap_size ).
    {Min_bin_vheap_size, 46368}
    Erlang: system_info (fullsweep_after ).
    {Fullsweep_after, 65535}
  45. The Erl-detached parameter is used to remove the dependency on the terminal.
  46. Erang performance tuning from ejabberd project http://www.ejabberd.im/tuning
  47. Note:Tail recursion as seen here is not making the memory grow because when the virtual machine sees a function calling itself in a tail position (the last expression to be evaluated in a function ), it eliminates the current stack frame. this is called tail-call optimisation (TCO) And it is a special case of a more general optimisation namedLast call Optimisation(LCO ).

    Lco is done whenever the last expression to be evaluated in a function body is another function call. when that happens, as with TCO, the Erlang VM avoids storing the stack frame. as such tail recursion is also possible between multiple functions. as an example, the chain of functionsa() -> b(). b() -> c(). c() -> a().Will wait tively create an infinite loop that won't go out of memory as LCO avoids overflowing the stack. This principle, combined with our use of accumulators is what makes tail recursion useful.

  48. Note:The correct ordering of each element in a comparison is the following:
    number < atom < reference < fun < port < pid < tuple < list < bit string

    You don't know all these types of things yet, but you will get to know them through the book. Just remember that this is why you can compare anything with anything! To quote Joe Armstrong, one of the creators of Erlang: "the actual order is not important-but that a total ordering is well defined is important ."

     

     

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.