There is difference in sytax when writing functions in Erlang module and Erlang shell (REPL). As P_A mentioned you need to call as F = fun(X) -> X end, F("Echo"). Also note that function names are atoms so has to start with lowercase when you are writing in Erlang module. If you are serious about learning Erlang I would suggest you go through this . You mentioned that you worked on F#. The basic difference between F# and Erlang in this case is that expression let Lilo = [|5; 3; -3; 0; 0.5|];; Can be written directly in the file and executed. In Erlang it can only be done in Erlang shell and not inside a file. So the expression you are trying should be inside a function inside a module with the same name as file. Consider test.erl file. Any function you export can be called from outside (shell).
-module(test).
-export([test/0]).
test() ->
Lilo = [5, 3, -3, 0, 0.5],
[X*2 || X <-Lilo].
2条答案
按热度按时间ifmq2ha21#
在REPL中,必须使用
fun(...) -> ... end
:如果文件中有代码,请使用
c
命令:8fq7wneg2#
There is difference in sytax when writing functions in Erlang module and Erlang shell (REPL). As P_A mentioned you need to call as
F = fun(X) -> X end, F("Echo").
Also note that function names are atoms so has to start with lowercase when you are writing in Erlang module. If you are serious about learning Erlang I would suggest you go through this .
You mentioned that you worked on F#. The basic difference between F# and Erlang in this case is that expression
let Lilo = [|5; 3; -3; 0; 0.5|];;
Can be written directly in the file and executed. In Erlang it can only be done in Erlang shell and not inside a file. So the expression you are trying should be inside a function inside a module with the same name as file. Consider test.erl file. Any function you export can be called from outside (shell).