PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.9.1
Code Block Pro – Beautiful Syntax Highlighting v1.9.1
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / build / shiki / samples / erlang.sample

erlang.sample in Code Block Pro – Beautiful Syntax Highlighting 1.9.1, at build/shiki/samples/erlang.sample

50 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 %% File: person.hrl
2
3 %%-----------------------------------------------------------
4 %% Data Type: person
5 %% where:
6 %% name: A string (default is undefined).
7 %% age: An integer (default is undefined).
8 %% phone: A list of integers (default is []).
9 %% dict: A dictionary containing various information
10 %% about the person.
11 %% A {Key, Value} list (default is the empty list).
12 %%------------------------------------------------------------
13 -record(person, {name, age, phone = [], dict = []}).
14
15 -module(person).
16 -include("person.hrl").
17 -compile(export_all). % For test purposes only.
18
19 %% This creates an instance of a person.
20 %% Note: The phone number is not supplied so the
21 %% default value [] will be used.
22
23 make_hacker_without_phone(Name, Age) ->
24 #person{name = Name, age = Age,
25 dict = [{computer_knowledge, excellent},
26 {drinks, coke}]}.
27
28 %% This demonstrates matching in arguments
29
30 print(#person{name = Name, age = Age,
31 phone = Phone, dict = Dict}) ->
32 io:format("Name: ~s, Age: ~w, Phone: ~w ~n"
33 "Dictionary: ~w.~n", [Name, Age, Phone, Dict]).
34
35 %% Demonstrates type testing, selector, updating.
36
37 birthday(P) when is_record(P, person) ->
38 P#person{age = P#person.age + 1}.
39
40 register_two_hackers() ->
41 Hacker1 = make_hacker_without_phone("Joe", 29),
42 OldHacker = birthday(Hacker1),
43 % The central_register_server should have
44 % an interface function for this.
45 central_register_server ! {register_person, Hacker1},
46 central_register_server ! {register_person,
47 OldHacker#person{name = "Robert",
48 phone = [0,8,3,2,4,5,3,1]}}.
49
50 %% From https://erlang.org/doc/programming_examples/records.html#a-longer-example