我不太清楚如何在Erlang模块中定义Erlang函数。我收到以下错误:
11> invoke_record:invoke().
** exception error: undefined function erlang:rr/1
从这个简单的代码中,尝试从beam可执行文件中调用rr(?MODULE).
,以便“初始化”记录,这样就不需要每次都从shell中调用它。
-module(invoke_record).
-export([invoke/0]).
-record(process, {pid,
reference="",
lifetime=0
}).
invoke() ->
erlang:rr(?MODULE).
4条答案
按热度按时间xesrikrc1#
The command
rr("file.hrl").
is meant to be be used only in shell for debugging purposes.As other users highlighted in their answers, the correct way to import a record (or a function) contained in a .hrl file within your erlang code consists in using the command
-include("file.hrl')
.Once you have included the
.hrl
file in your code (and usually in a module based on OTP behaviours this is done after the-export(...)
part) you can refer to the Erlang record (or function) without any problem.wswtfjt72#
rr
是shell命令。不能在编译代码时使用。http://www.erlang.org/doc/man/shell.html
guicsvcw3#
If your intent is to read many record definitions in the shell, in order to facilitate the debug, you can write a file containing all needed include statements and simply invoke rr once in the shell.
in rec.hrl:
and in the in the shell
I didn't find any way to execute this automatically, when starting the VM.
lymnna714#
在处理项目时,您可以将所有必要的include和其他要用于该特定项目的命令行参数收集到一个纯文本文件中。创建纯文本文件后,您可以启动shell:
其中FileName是纯文本文件的名称。请注意,允许使用erl接受的所有命令行参数。另请参阅the ERTS Reference Manual中的erl标志