Étude 2-1: Writing a Function
Write a module with a function that takes the length and width of a
rectangle and returns (yields) its area. Name the module geom
, and
name the function area
. The function has arity 2, because it needs
two pieces of information to make the calculation. In Erlang-speak:
write function area/2
.
Here is some sample output.
1
>
c
(
geom
).
{
ok
,
geom
}
2
>
geom
:
area
(
3
,
4
).
12
3
>
geom
:
area
(
12
,
7
).
84
Get Études for Erlang now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.