2021-09-01 14:59:04 +00:00
|
|
|
=====================================
|
|
|
|
no arguments
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn() -> 1 end
|
|
|
|
fn () -> 1 end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments)
|
|
|
|
(body
|
|
|
|
(integer))))
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
2021-09-25 00:23:37 +00:00
|
|
|
(arguments)
|
2021-09-01 14:59:04 +00:00
|
|
|
(body
|
|
|
|
(integer)))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
no arguments without parentheses
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn -> 1 end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(body
|
|
|
|
(integer)))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
one argument
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn(x) -> x end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(identifier))
|
|
|
|
(body
|
|
|
|
(identifier)))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
one argument without parentheses
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn x -> x end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(identifier))
|
|
|
|
(body
|
|
|
|
(identifier)))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
many arguments
|
|
|
|
=====================================
|
|
|
|
|
2021-09-28 18:40:20 +00:00
|
|
|
fn(x, y, z) -> x + y end
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
2021-09-28 18:40:20 +00:00
|
|
|
(identifier)
|
2021-09-01 14:59:04 +00:00
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(body
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(identifier))))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
many arguments without parentheses
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn x, y -> x + y end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(body
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(identifier))))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
multiline body
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn x, y ->
|
|
|
|
y
|
|
|
|
x
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(body
|
|
|
|
(identifier)
|
|
|
|
(identifier)))))
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
many clauses
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
1 -> :yes
|
|
|
|
2 -> :no
|
|
|
|
other -> :maybe
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(integer))
|
|
|
|
(body
|
2021-09-28 14:00:35 +00:00
|
|
|
(atom)))
|
2021-09-01 14:59:04 +00:00
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(integer))
|
|
|
|
(body
|
2021-09-28 14:00:35 +00:00
|
|
|
(atom)))
|
2021-09-01 14:59:04 +00:00
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(identifier))
|
|
|
|
(body
|
2021-09-28 14:00:35 +00:00
|
|
|
(atom)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
with guard / no arguments
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
() when node() == :nonode@nohost -> true
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments)
|
|
|
|
(binary_operator
|
|
|
|
(call
|
|
|
|
(identifier)
|
|
|
|
(arguments))
|
2021-09-28 14:00:35 +00:00
|
|
|
(atom)))
|
2021-09-01 14:59:04 +00:00
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(boolean)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
with guard / one argument
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
x when x == [] -> x
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments
|
|
|
|
(identifier))
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(list)))
|
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(identifier)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
with guard / multiple arguments
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
x, y when x == [] -> x
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(list)))
|
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(identifier)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
with guard / arguments in parentheses
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
(x, y) when y == [] -> y
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(list)))
|
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(identifier)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
with guard / multiple guards
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
x when x > 10 when x < 5 -> x
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments
|
|
|
|
(identifier))
|
|
|
|
(binary_operator
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
2021-09-25 00:23:37 +00:00
|
|
|
(integer))
|
2021-09-01 14:59:04 +00:00
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
2021-09-25 00:23:37 +00:00
|
|
|
(integer))))
|
2021-09-01 14:59:04 +00:00
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(identifier)))))
|
2021-09-01 14:59:04 +00:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
pattern matching
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
fn
|
|
|
|
[h | tail] -> {h, tail}
|
|
|
|
%{x: x} when x == 1 -> 1
|
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(source
|
|
|
|
(anonymous_function
|
|
|
|
(stab_clause
|
|
|
|
(arguments
|
|
|
|
(list
|
|
|
|
(binary_operator
|
|
|
|
(identifier)
|
|
|
|
(identifier))))
|
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(tuple
|
|
|
|
(identifier)
|
|
|
|
(identifier))))
|
2021-09-01 14:59:04 +00:00
|
|
|
(stab_clause
|
|
|
|
(binary_operator
|
|
|
|
(arguments
|
|
|
|
(map
|
|
|
|
(map_content
|
|
|
|
(keywords
|
|
|
|
(pair
|
2021-09-28 14:00:35 +00:00
|
|
|
(keyword)
|
2021-09-01 14:59:04 +00:00
|
|
|
(identifier))))))
|
|
|
|
(binary_operator
|
2021-09-25 00:23:37 +00:00
|
|
|
(identifier)
|
|
|
|
(integer)))
|
2021-09-01 14:59:04 +00:00
|
|
|
(body
|
2021-09-25 00:23:37 +00:00
|
|
|
(integer)))))
|