Erlang Crash Dump 正在写入: erl_crash.dump...done

Var*_*han 3 erlang intellij-idea

所以我才开始学习一些基本的 Erlang。我正在研究 IntelliJ Idea。我写了一个基本函数来添加两个数字:

-module(easy).
-author("var").

%% API
-export([add/2]).

add(X, Y) ->
  X + Y.
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,出现以下错误:

{"init terminating in do_boot",{{badmatch,{error,{1,erl_parse,["syntax error before: ","','"]}}},[{init,start_it,1,[]},{init,start_em,1,[]}]}}

Crash dump is being written to: erl_crash.dump...done
init terminating in do_boot ()
Run Code Online (Sandbox Code Playgroud)

我似乎无法弄清楚为什么会发生这种情况。是否与 Idea 的运行配置有关?

Gre*_*reg 5

不知道你是如何执行代码的。尝试按照以下步骤操作。

创建包含源代码的文件,在本例中为easy.erl,您已经拥有:

[g@somecomp:~/test]$ cat easy.erl 
-module(easy).
-author("var").

%% API
-export([add/2]).

add(X, Y) ->
    X + Y.
Run Code Online (Sandbox Code Playgroud)

现在编译模块:

[g@somecomp:~/test]$ erlc easy.erl
Run Code Online (Sandbox Code Playgroud)

启动 Erlang 并从 shell 加载它:

[g@somecomp:~/test]$ erl
Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.2.1  (abort with ^G)
1> l(easy).
{module,easy}
Run Code Online (Sandbox Code Playgroud)

在 shell 中执行函数并关闭 Erlang:

2> easy:add(1,2).
3
3> q().
ok
4> [g@somecomp:~/test]$ 
Run Code Online (Sandbox Code Playgroud)

或者,您可以直接从 shell ( bash, csh)执行它,但在这种情况下,您必须明确打印出返回值:

[g@somecomp:~/test]$ erlc easy.erl
[g@somecomp:~/test]$ erl -noshell -eval 'io:format("~p~n", [easy:add(1,2)])' -s init stop
3
[g@somecomp:~/test]$
Run Code Online (Sandbox Code Playgroud)