Summary of data types for fun-functions

Source: Internet
Author: User

1. Anonymous fun function

A. Anonymous functions and variable bindings

What we generally see is assigning an anonymous function to a variable: the equivalent of this variable is the function name of the future.

This variable is then used as the function name. For example:

Double=fun (X)->2*x end. Double (2). The result is 1.

B. Anonymous fun function as function parameter

L=[1,2,3,4].list:map (Fun (X)->2*x end,l).

In short, to be anonymous function, you must bind to the variable, or as a parameter is passed to other functions, and also must not forget that the function body of the anonymous function has an end as its end.

2. The fun function of function aliases

A. This module applies

If you want to apply a function that is already defined inside this module, pass it directly to another function as a parameter, in the following form

Make (Name), register (Name,spawn ()->my_handler (fun NO_OP/1)). No_op (_)->void.my_handler (fun)-&G    T Receive {event,any}-> catch fun (any) end.

The fun no_op/1 of the My_handler () function parameter is quite the function alias of the No_op (_) function. When assigned to a variable, you can call this function with the same alias as you would call any normal function.

Note: The local alias fun function is similar to the anonymous happy function in implementation, and they all depend on the current version of the module.

B. Other module applications

1-module (Test).  2 3-export ([TEST/1]).  4 5 test (x) when x > 2-true; 6 7 Test (X), false.

If applied in the shell:

Note: When called, they are not dependent on a specific version. Instead, it always points to the latest version of the reference function.





























Summary of data types for fun-functions

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.