@@ -2028,19 +2028,57 @@ defmodule Kernel do
2028
2028
x -> x * 2
2029
2029
end)
2030
2030
2031
- ## Function retrieval
2031
+ """
2032
+ defmacro function(args)
2032
2033
2033
- The `function` macro can also be used to retrieve local or remote
2034
- functions:
2034
+ @doc """
2035
+ Retrieves a local or an imported function.
2036
+
2037
+ ## Examples
2035
2038
2036
2039
f = function(:is_atom, 1)
2037
2040
f.(:foo) #=> true
2038
2041
2039
- f = function(List, :flatten, 1)
2040
- f.([1,[2],3]) #=> [1,2,3]
2042
+ Notice that local functions cannot be retrieved dynamically,
2043
+ the following, for example, wouldn' t work:
2044
+
2045
+ some_fun = :is_atom
2046
+ function ( some_fun , 1 )
2047
+
2048
+ In such cases, one should use `function / 3 `:
2049
+
2050
+ some_fun = :is_atom
2051
+ function( SomeModule , some_fun , 1 )
2052
+
2053
+ ## Shortcut syntax
2054
+
2055
+ One can use a shortcut syntax to retrieve such functions ,
2056
+ that resembles Erlang 's `fun`:
2057
+
2058
+ f = function(is_atom/1)
2059
+ f.(:foo)
2041
2060
2042
2061
"""
2043
- defmacro function(args)
2062
+ defmacro function(function, arity)
2063
+
2064
+ @doc """
2065
+ Retrieves a function from a module.
2066
+
2067
+ ## Examples
2068
+
2069
+ f = function(Kernel, :is_atom, 1)
2070
+ f.(:foo) #=> true
2071
+
2072
+ ## Shortcut syntax
2073
+
2074
+ One can use a shortcut syntax to retrieve such functions,
2075
+ that resembles Erlang's `fun`:
2076
+
2077
+ f = function ( Kernel . is_atom / 1 )
2078
+ f. ( :foo ) #=> true
2079
+
2080
+ """
2081
+ defmacro function(module, function, arity)
2044
2082
2045
2083
@doc """
2046
2084
Matches the given condition against the match clauses.
0 commit comments