[b]Literal Term[/b]
int, float, atom, tuple, list, binary
in predefined attributes and user-defined attributes, the Value must be literal term. for example:
some_module.erl
...
-attr1(1).
-attr2(1.0).
-attr3(correct).
-attr4({1, 0}).
-attr5("good").
-attr6(<<"good">>).
...
all the attributes is normal.
[b]List Comprehension[/b]
for example:
L = [{cn, "Beijing"}, {cn, "Shanghai"}, {us, "New York"}, {jp, "Tokyo"}].
a) CnCity = [Ci || {cn, Ci} <- L] or
b) CnCity = [Ci || {Country, Ci} <-L, Country =:= cn]
a) we can use pattern match in generator to get some Values, this is simple.
b) we can also use filter to get the expected values.
[b]Macros With Same Name[/b]
In Erlang, if two macros with the same name, then we will get "redefing macro .." error info when compilation. so we must give the different names for all the macro.
for example:
-define(Log(S), (io:format("log:~s~n", [S]))).
-define(Log(F, D), (io:format("log:~s~n", [io_lib:format(F, D)]))).
change to
-define(Log(S), (io:format("log:~s~n", [S]))).
-define(Log2(F, D), (io:format("log:~s~n", [io_lib:format(F, D)]))).
[b]Macros Can't use in function internal[/b]
e.g.
will occur a syntax error.
int, float, atom, tuple, list, binary
in predefined attributes and user-defined attributes, the Value must be literal term. for example:
some_module.erl
...
-attr1(1).
-attr2(1.0).
-attr3(correct).
-attr4({1, 0}).
-attr5("good").
-attr6(<<"good">>).
...
all the attributes is normal.
[b]List Comprehension[/b]
for example:
L = [{cn, "Beijing"}, {cn, "Shanghai"}, {us, "New York"}, {jp, "Tokyo"}].
a) CnCity = [Ci || {cn, Ci} <- L] or
b) CnCity = [Ci || {Country, Ci} <-L, Country =:= cn]
a) we can use pattern match in generator to get some Values, this is simple.
b) we can also use filter to get the expected values.
[b]Macros With Same Name[/b]
In Erlang, if two macros with the same name, then we will get "redefing macro .." error info when compilation. so we must give the different names for all the macro.
for example:
-define(Log(S), (io:format("log:~s~n", [S]))).
-define(Log(F, D), (io:format("log:~s~n", [io_lib:format(F, D)]))).
change to
-define(Log(S), (io:format("log:~s~n", [S]))).
-define(Log2(F, D), (io:format("log:~s~n", [io_lib:format(F, D)]))).
[b]Macros Can't use in function internal[/b]
e.g.
some_fun() ->
-ifdef(debug).
io:format("some text~n"),
-endif.
....
will occur a syntax error.