trouble when using anonymous functions inside erlang modules

不打扰是莪最后的温柔 提交于 2019-12-06 11:32:21

An Erlang module cannot export variables, only functions.

You can achieve something similar to exporting variables by exporting a function with zero arguments that simply returns a value (an anonymous function is a valid return value):

-module(qt).
-export([ra/0]).
ra() ->
    fun() -> 4 end.

Now you can use it from the shell:

1> c(qt).
{ok,qt}
2> qt:ra().
#Fun<qt.0.111535607>
3> (qt:ra())().
4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!