【发布时间】:2020-06-16 12:00:50
【问题描述】:
给定以下erlang函数
-module(fibonacci).
-export([my_function_3/1]).
my_function_3(Arg1) when Arg1==3 -> io:format("=3");
my_function_3(Arg1) when Arg1<3 -> io:format("<3");
my_function_3(Arg1) when Arg1>3 -> io:format(">3").
从命令行调用 my_function_3 函数显示的值与从 shell 调用时不同(见下文)。
请注意,我使用2、3 和4 作为参数,以便在所有定义中对函数进行评估。
从erlang shell 调用my_function_3
$ erl
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V10.6.2 (abort with ^G)
1> c(fibonacci).
{ok,fibonacci}
2> fibonacci:my_function_3(2).
<3ok
3> fibonacci:my_function_3(3).
=3ok
4> fibonacci:my_function_3(4).
>3ok
从命令行调用my_function_3
$ erlc fibonacci.erl
$ erl -noshell -s fibonacci my_function_3 2 -s init stop
>3%
$ erl -noshell -s fibonacci my_function_3 3 -s init stop
>3%
$ erl -noshell -s fibonacci my_function_3 4 -s init stop
>3%
因此,我的问题是:为什么erlang 从命令行调用函数和从erlang shell 调用时输出不同的值?
【问题讨论】:
标签: erlang erlang-shell erl