更新时间:2022-03-07 21:02:15
每个Erlang模块,如这里应该包含一系列属性和函数声明,每个都由句号(。)终止。
Each Erlang module, as described here, should consist of a sequence of attributes and function declarations, each terminated by period (.)
但这行:
Foo = fun(X) -> X * X end.
...既不是,也应该写成如下:
... is neither and should be written as follows instead:
foo(X) -> X * X.
foo
是小写在这里因为此行是函数声明,其中函数名应为原子码。
foo
is lowercase here, because this line is a function declaration, where function name should be an atom.
所以最后你的模块看起来像这样:
So in the end your module will look like this:
-module(bakery).
-export([cake/1]).
foo(X) -> X * X.
cake(0) -> [];
cake(N) when N > 0 -> [ foo(2) | cake(N-1) ].