Erlang tip Accumulation

Source: Internet
Author: User

1. Erl-detached

This document describes the applicability of daemons and background programs. It also applies when node is dynamically pulled in the Code. Otherwise, the problem of terminate Erlang will be reported.

2 init stop

Can terminate the VM, combined with RPC: Call can end the specified Node

3. control common test in code

CT: Install specifies the config file, CT: start_interactive (). This is very important. It specifies the interaction mode.

4 and/not

You need to enclose the comparison operators between the left and right sides ().

5 wxwidget

For more information about how to port the Erlang GUI library, see the wxwidget official documentation.

6 $ get ASCII

Specifies the ASCII value of char. For example, if $0 is 48, it is very useful when processing binary.

Tip of 7 [H | T]

[H | T] = List common usage. You can also use [key1, _, key2 | T] = List to match the matching data.

8 debugger debugging gen_server: Call

Use gen_server: Call/3, timeout can use infinity, default is 5 S, basically not enough debugging

9 debugger associate with other nodes

When the VM is daemon, you cannot start the debugger through the command line. You can use RPC: Call (node, debugger, start, []) to start the debugger, prompting at node @ host.

10 get the state of OTP processes such as gen_server/gen_fsm

SYS: get_status/1, 2, applicable to all OTP processes and process based on proc_lib and sys

11 how to set timer

Use Erlang: send_after/3 and Erlang: start_timer/3 instead of the timer module. Timer uses an independent process to manage timer. If many processes frequently establish or cancel timer, it may cause overload.

12-tail recursion

When tail recursion does not need to be reversed, the efficiency is higher than normal recursion. Otherwise

13 atom, ETS does not have automatic garbage collection

You need to consider how to avoid meaningless atom and ETS. ETS to display the specified Delete

14 binary <> Format

= And <> must be separated by Spaces

15 <X: 7/binary, Y: 1/binary> is invalid.

In the pattern match that contains binary, it must be a multiple of 8; otherwise, it cannot be parsed.

16 gen_server: Call Remote Call

Serverref = Name | {name, node} | {Global, globalname} | {via, module, vianame} | PID ()

If you want to call gen_server of another node to send messages, you thought you needed RPC to call remote gen_server: Call. After carefully studying the function description, you can find that {name, node} and {Global are supported, globalname} is easy to use. 

17 Message format received by gen_tcp

    {tcp, Socket, Data}
    {tcp_closed, Socket}
    {tcp_error, Socket, Reason}

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.