【问题标题】:Simple Erlang example won't run (error)简单的 Erlang 示例无法运行(错误)
【发布时间】:2014-12-19 15:50:45
【问题描述】:

大家下午好,

我最近对 ​​Erlang 和函数式编程产生了兴趣。我试图在不打开 Erlang shell 的情况下运行这个简单的 hello world 示例。我能够在 MACOSX (Yosemite) 中成功运行它,但我想改用我的 Fedora 20 VM。因此,在 Fedora (Linux)(甚至 Windows 7)中,尝试运行已编译的梁时出现以下错误:

{"init terminating in do_boot",{undef,[{heythere,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()

这些是我用来运行文件的开关:

erl -noshell -start -s heythere -init -stop

我什至替换了“-s”开关并使用“-run”无济于事。我可以在 shell 内运行模块,但不能在 shell 之外运行。是不是我做错了什么?

代码:

-module(heythere).
-export([hello_world/0, this_function/0, both/0]).

hello_world() -> 
  io:fwrite("hello, world\n").

this_function() -> 
  io:fwrite("This is another function...ok~n").

both() ->
  hello_world(),
  this_function().

我尝试查看 erl_crash.dump,但它的长度超过 1000 多行,我无法确定它的正面或反面。 :-(

提前非常感谢你们。

【问题讨论】:

    标签: linux functional-programming erlang


    【解决方案1】:

    -s 标志中,您指定了一个模块heythere,但没有要使用的函数。 erl 默认使用start 作为函数,但是你没有在你的模块中指定start 函数,所以erl 不知道如何运行你的程序。

    【讨论】:

    • 非常感谢 mipadi!那行得通!难怪我的例子只适用于 MACOSX。因为它有一个启动功能,而这个最近的例子没有!你真好。 :-)
    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2013-10-19
    • 2020-03-08
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多