erlang本身提供一个接口,可以用来检查模块是否有导出函数,这个接口是erlang:function_exported/3,但是很多时候这个接口无法正常使用。 下面重现一下这个问题: 1> erlang:function_exported(crypto,start,0). false 2> crypto:start(). ok 3> erlang:function_exported(crypt
Applying an exported function (Mod:Name(),apply(Mod, Name, [])) is about twice as expensive as calling a fun, or aboutsix timesas expensive as calling a local function. DocLink:http://www.erlang.org/doc/efficiency_guide/functions.html 概念明确 对于上面的结论,明确一下上面表中跨模块调用这...
Really! Of course it's useless without functions. Let's first decide what functions will be exported from our 'useless' module. To do this, we will use another attribute:-export([Function1/Arity, Function2/Arity, ..., FunctionN/Arity]). This is used to define what functions of a ...
假设你有一个世界上各个城市的温度值的列表。其中,一部分是以摄氏度表示,另一部分是华氏温度表示的。首先,我们将所有的温度都转换为用摄氏度表示,再将温度数据输出。 %% Thismoduleisinfile tut5.erl -module(tut5). -export([format_temps/1]). %% Onlythisfunctionisexported format_temps([])-> % No ou...
% A "Hello world" function some_fun() -> io:format('~s~n', ['Hello world!']). % This one works only with lists some_fun(List) when is_list(List) -> io:format('~s~n', List). % Non-exported functions are private priv() -> ...
Applying an exported function (Mod:Name(),apply(Mod, Name, [])) is about twice as expensive as calling a fun, or aboutsix timesas expensive as calling a local function. (%% 这边以及下面所指的fun,应该是Module:Function(Arguments)这种形式的函数,其中M,F,A可以是变量类型,值不是固定的 %%) ...
Erlang内置函数spawn用于创建一个新进程:spawn(Module, Exported_Function, List of Arguments)。考虑下面的模块 -module(tut14).-export([start/0,say_something/2]).say_something(What,0)->done;say_something(What,Times)->io:format("~p~n",[What]),say_something(What,Times-1).start()->spawn(tut...
erlang:function_exported/3检测一个函数是否输出并被加载 erlang:garbage_collect/0对当前进程进行垃圾回收操作 erlang:garbage_collect/1对指定进程进行垃圾回收操作 erlang:get/0返回进程里的所有字典值 erlang:get/1从进程字典里获取一个值 erlang:get_cookie/0获取本地节点的魔饼值(magic cookie) erlang:get_keys...
Erlang 的内置函数 spawn 可以用来创建一个新的进程: spawn(Module, Exported_Function, List of Arguments)。假设有如下这样一个模块: -module(tut14). -export([start/0, say_something/2]). say_something(What, 0) -> done; say_something(
% A "Hello world" function some_fun() -> io:format('~s~n', ['Hello world!']). % This one works only with lists some_fun(List) when is_list(List) -> io:format('~s~n', List). % Non-exported functions are private priv() -> ...