-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathfunctions.ex
More file actions
62 lines (47 loc) · 828 Bytes
/
functions.ex
File metadata and controls
62 lines (47 loc) · 828 Bytes
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
defmodule Funcs do
def no_args() do
end
def no_args_no_parens do
end
def one_arg(x) do
x
end
def one_arg_no_parens(x) do
x
end
def two_args(x, y) do
x + y
end
def two_args_no_parens(x, y) do
x + y
end
def default_args_no_parens(x, y \\ 1) do
x + y
end
def default_args(x, y \\ 1) do
x + y
end
def do_block(), do: 1
def do_block(x), do: x
def pattern_matching([{x, y} | tail]) do
x + y
end
def one_guard(x) when x == 1 do
x
end
def multiple_guard(x) when x > 10 when x < 5 do
x
end
defp private(x) do
x
end
defmacro macro(x) do
quote do
[unquote(x)]
end
end
defguard guard(term) when is_integer(term) and rem(term, 2) == 0
def unquote(name)(unquote_splicing(args)) do
unquote(compiled)
end
end