More Related Content Similar to Erlang Introduction Bcberlin3 (20) Erlang Introduction Bcberlin316. 10> 1 + 2 * 3.
7
11> 2 * 3 + 1.
7
12> (1 + 2) * 3.
9
16
17. 13> 3/0.
** exception error: bad argument in an
arithmetic expression
in operator '/'/2
called as 3 / 0
17
18. 4> catch 3/0.
{'EXIT',{badarith,[{erlang,'/',[3,0]},
{erl_eval,do_apply,5},
{erl_eval,expr,5},
{shell,exprs,6},
{shell,eval_exprs,6},
{shell,eval_loop,3}]}}
18
29. 1> Mod = lists.
lists
2> Fn = reverse.
reverse
3> Mod:Fn(quot;tacquot;).
quot;catquot;
29
32. 39> Fn = fun lists:reverse/1.
#Fun<lists.reverse.1>
40> apply(Fn, [quot;olleHquot;]).
quot;Helloquot;
32
34. 48> N = 1.
1
49> N = 2.
** exception error: no match of right
hand side value 2
50> N = 1.
1
34
36. 1> Coffee = harem:espresso().
{espresso, quot;Haremquot;, orange}
2> {espresso, _, Crema} = Coffee.
{espresso, quot;Haremquot;, orange}
3> Crema.
orange
36
39. 5> L = [101, left, right, quot;abcquot;].
[101,left,right,quot;abcquot;]
6> lists:nth(1,L).
101
39
42. 38> [First, Sec | Rest] = quot;Restquot;.
quot;Restquot;
39> First.
82
40> [First].
quot;Rquot;
41> Sec.
101
42> [Sec].
quot;equot;
42
46. 1> P = {adam,24,{july,29}}.
{adam,24,{july,29}}
2> element(1,P).
adam
46
48. 4> P2 = setelement(2,P,25).
{adam,25,{july,29}}
48
53. web_request(Req) ->
Req:ok({quot;text/htmlquot;,
<<quot;<html>
<head><title>
Hello Berlin
</title></head>
<body>
Hello Berlin
</body>
</html>quot;>>}).
53
55. 0000000 d4 c3 b2 a1 02 00 04 00 00 00 00 00 00 00 00 00
0000010 60 00 00 00 01 00 00 00 07 aa f7 48 b4 32 08 00
0000020 4e 00 00 00 4e 00 00 00 00 14 6c 62 ef 18 00 19
0000030 e3 07 c0 bc 08 00 45 00 00 40 30 0d 40 00 40 06
0000040 3e 4e c0 a8 b2 cb d1 55 87 93 cd b9 00 50 a1 59
0000050 7f 98 00 00 00 00 b0 02 ff ff ad c0 00 00 02 04
0000060 05 b4 01 03 03 03 01 01 08 0a 27 c0 a6 25 00 00
0000070 00 00 04 02 00 00
0000076
55
56. <<Version:4, IHLen:4,
TOService:8, TotalLength:16,
Id:16, Flags:3, FragOffset:13,
Ttl:8, Protocol:8,
HeaderChecksum:16,
SourceAddr:32,
DestAddr:32>> = H.
56
57. 43> A = 0.
0
44> B = 8.
8
45> C = 15.
15
46> Msg = <<A:9, B:12, C:16>>.
<<0,0,64,0,15:5>>
57
65. double(X) ->
2 * X.
greet(Name) ->
io:fwrite(quot;Hallo ~p~nquot;, [Name]),
ok.
65
66. 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
66
67. fib(0) ->
0;
fib(1) ->
1;
fib(N) when is_integer(N) ->
fib(N-1) + fib(N-2).
67
70. vowels(Text) ->
vowels(Text, []).
vowels([H|T], Acc) ->
Acc1=case member(H, quot;aeiuoquot;) of
true -> [H | Acc];
false -> Acc
end,
vowels(T, Acc1);
vowels([], Acc) ->
reverse(Acc).
70
86. receive
{lookup, Query} ->
query(Query);
{update, Update} ->
update(Update)
end
86
103. L = [1,2,3,4,5],
L1 = lists:map(fun(E) ->
E * 2
end, L).
[2,4,6,8,10]
103
115. init(_Args) ->
{ok, {{one_for_one, 1, 60},
[{ch3, {ch3, start_link, []},
permanent, brutal_kill,
worker, [ch3]}]
}}.
115
121. kernel
erlang
code file
rpc
application io
inet
error_logger
121
122. stdlib
math dict
filename sets
string
lists proplists
dets regexp
random shell
array
queue timer
gen_server
122
126. succeed() ->
ok.
fail() ->
throw(failed).
succeeding_test() ->
succeed().
failing_test() ->
fail().
126
127. succeeding_assert_test_() ->
?_assert(1 > 0).
failing_assert_test_() ->
?_assert(0 > 1).
succeeding_error_test_() ->
?_assertError(foo,
erlang:error(foo)).
failing_error_test_() ->
?_assertError(foo,
erlang:throw(foo)).
127
134. $ sudo port install mochiweb
$ escript /opt/local/share/scripts/
new_mochiweb.erl my
app$ cd myapp ; make
$ sh start-dev.sh
$ open localhost:8000
134
150. ports
edoc
debugger
erlang-mode
distel
type specs
dialyzer
mochiweb
yaws
Lisp Flavoured Erlang
Reia
150
158. 11> {ok,File} =
file:open(quot;PROJECTSquot;, [read]).
{ok,<0.92.0>}
13> io:get_line(File, []).
quot;Intro Erlang (am Mi., 17.10.08)nquot;
15> file:close(File).
158