-
Notifications
You must be signed in to change notification settings - Fork 0
/
records.erl
39 lines (31 loc) · 1.03 KB
/
records.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-module(records).
-compile(export_all).
-include("records.hrl").
-record(robot, {name,
type=industrial,
hobbies,
details=[]}).
-record(user, {id, name, group, age}).
first_robot() ->
#robot{name="Mechatron",
type=handmade,
details=["Moved by a small man inside"]}.
car_factory(CorpName) ->
#robot{name=CorpName, hobbies="building cars"}.
%% use pattern matching to filter
admin_panel(#user{name=Name, group=admin}) ->
Name ++ " is allowed!";
admin_panel(#user{name=Name}) ->
Name ++ " is not allowed".
%% can extend user without problem
adult_section(U = #user{}) when U#user.age >= 18 ->
%% Show stuff that can't be written in such a text
allowed;
adult_section(_) ->
%% redirect to sesame street site
forbidden.
repairman(Rob) ->
Details = Rob#robot.details,
NewRob = Rob#robot{details=["Repaired by repairman"|Details]},
{repaired, NewRob}.
included() -> #included{some_field="Some value"}.