Elixir 1.6.1
is_function() works fine on declared variables but in fact, if the variable is not defined in the program, it outputs an error (interactive shell in my case)
Code sample
is_function(sum)
#(CompileError) iex:1: undefined function add/0
# may be it should return false
sum = 1
is_function(sum)
# false
sum = fn ... end
is_function(sum)
#true
This is a suggestion, let me know if this is not the appropriate place to write suggestions ;)
either output "false" on undeclared variables, Ex:
is_function(sum)
# false
consider supporting atomic input:
is_function(:sum) # ruby way:)
as far as i know the naming conventions for atoms and variables are same, and thus this solution wont have bad 械ffects.
@m13m updated, my bad, miss-clicked and posted issue early)
Yes, is_function expects a value. You can't pass a variable that was not defined because that's a compilation error.
Ruby conventions doesn't work here because there is no object to ask what the function is. Unless you retrieve the function as an actual value, they do not exist at runtime. So for example, if you are inside a module that defines a function like this:
def add(a, b) do
a + b
end
In order for it to be a value, you need to retrieve it as &add/2.
Most helpful comment
Yes, is_function expects a value. You can't pass a variable that was not defined because that's a compilation error.
Ruby conventions doesn't work here because there is no object to ask what the function is. Unless you retrieve the function as an actual value, they do not exist at runtime. So for example, if you are inside a module that defines a function like this:
In order for it to be a value, you need to retrieve it as
&add/2.