7
I’m studying the module Enum
of the Elixir language in which it provides various functions that allows working with enumerables, However, one thing caught my attention in the call of some of the functions.
The function any
when calling she is required to inform a ?
otherwise of the error, see the examples:
array = [1, 23, 54, 1, 121]
r = Enum.any?(array,
fn(v) ->
v > 100
end
)
IO.puts(r)
Exit:
true
Without the ?
in function call:
r = Enum.any(array,
fn(v) ->
v > 100
end
)
Exit:
** (UndefinedFunctionError) function Enum.any/2 is undefined or private. Did you mean one of:
* any?/1
* any?/2
(elixir) Enum.any([1, 23, 54, 1, 121], #Function<1.115443437 in file:main.exs>)
main.exs:26: (file)
(elixir) lib/code.ex:363: Code.require_file/2
Doubts
- What is the purpose of
?
in a function? - What is the relationship of
?
with the signature of the function? - What the
?
plays a special role?
The interesting thing is that in other languages the ? at the end of the syntax name invalidates.
– gato
Yes, for the most part.
– Maniero