-module(helloworld).
-export([start/0]).
start() ->
A = 5,
B = 6,
if
A == B ->
io:fwrite("True");
-module(helloworld).
-export([start/0]).
start() ->
A = 5,
B = 6,
if
A == B ->
io:fwrite("A is equal to B");
-module(helloworld).
-export([start/0]).
start() ->
A = 4,
B = 6,
if
A < B ->
if
A > 5 ->
-module(helloworld).
-export([start/0]).
start() ->
A = 5,
case A of
5 -> io:fwrite("The value of A is 5");
-module(helloworld).
-export([add/2,start/0]).
add(X,Y) ->
Z = X+Y,
io:fwrite("~w~n",[Z]).
% Erlang整数
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("~w",[1+1]).
-module(helloworld).
-export([tail_reverse/2,start/0]).
tail_reverse(L) -> tail_reverse(L,[]).
tail_reverse([],Acc) -> Acc;
-module(helloworld).
-export([duplicate/2,start/0]).
duplicate(0,_) ->
[];
duplicate(N,Term) when N > 0 ->
-module(helloworld).
-export([tail_len/1,tail_len/2,start/0]).
tail_len(L) -> tail_len(L,0).
tail_len([], Acc) -> Acc;
-module(helloworld).
-export([len/1,start/0]).
len([]) -> 0;
len([_|T]) -> 1 + len(T).
start() ->
-module(helloworld).
-export([fac/1,start/0]).
fac(N) when N == 0 -> 1;
fac(N) when N > 0 -> N*fac(N-1).
-module(helloworld).
-import(io,[fwrite/1]).
-export([start/0]).
start() ->
fwrite("Hello, world!\\n").
-module(helloworld).
-author("TutorialPoint").
-version("1.0").
-export([start/0]).
-module(helloworld).
-author("TutorialPoint").
-version("1.0").
-export([start/0]).
% Erlang模块定义 - helloworld
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("Hello World").
-module(helloworld).
-export([add/1,start/0]).
add(X) when X>3 ->
io:fwrite("~w~n",[X]).
-module(helloworld).
-export([add/2,add/3,start/0]).
add(X,Y) ->
Z = X+Y,
io:fwrite("~w~n",[Z]).
-module(helloworld).
-export([start/0]).
start() ->
Fn = fun() ->
io:fwrite("Anonymous Function") end,
% 关系运算符
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("~w~n",[3==2]),
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("~w~n",[true or false]),
io:fwrite("~w~n",[true and false]),
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("~w~n",[00111100 band 00001101]),
-module(helloworld).
-export([while/1,while/2, start/0]).
while(L) -> while(L,0).
while([], Acc) -> Acc;
-module(helloworld).
-export([for/2,start/0]).
for(0,_) ->
[];
for(N,Term) when N > 0 ->
io:fwrite("Hello~n"),
-module(helloworld).
-import(string,[concat/2]).
-export([start/0]).
start() ->
Str1 = "This is a ",
-module(helloworld).
-import(string,[equal/2]).
-export([start/0]).
start() ->
Str1 = "This is a string1",
-module(helloworld).
-import(string,[len/1]).
-export([start/0]).
start() ->
Str1 = "This is a string1",
-module(helloworld).
-export([start/0]).
start() ->
Str1 = "This is a string",
io:fwrite("~p~n",[Str1]).
-module(helloworld).
-export([start/0]).
start() ->
Num = 3,
io:fwrite("~w",[is_integer(Num)]).
-module(helloworld).
-export([start/0]).
start() ->
Num = 3.00,
io:fwrite("~w",[is_float(Num)]).
-module(helloworld).
-export([start/0]).
start() ->
Num = float(3),
io:fwrite("~f",[Num]).