I written a function to return the arity of a given function:
function arity(f)
if f == + return 2 # arithmetic functions
if f == - return 2
if f == * return 2
if f == / return 2
if f == ^ return 2
if f == % return 2
if f == sin return 1 # trig functions
if f == cos return 1
if f == tan return 1
end
It works fine for +, -, sin, cos, and tan, but fails for the others with the error message: ERROR: syntax: “*” is not a unary operator.
Why doesn’t this work for all the included functions?
Note the indexing [1] picking the first out of many methods in the method list. The -1 is required since I believe the function itself counts as one argument.