Add a public `arity` getter to the Fn class that returns the number of required arguments for a function. Internally rename the `numParams` field to `arity` across the codebase for consistency, update the C API parameter name from `numParams` to `arity` in `wrenDefineMethod` and `wrenDefineStaticMethod`, and adjust the error message in `callFunction` to use the new field name. Also update documentation to clarify that extra arguments are ignored rather than causing an error, and add a new test file `test/function/arity.wren` verifying arity values from 0 to 4.
826 B
826 B
^title Fn Class ^category core
A first class function—an object that wraps an executable chunk of code. Here is a friendly introduction.
new Fn(function)
Creates a new function from... function. Of course, function is already be
a function, so this really just returns the argument. It exists mainly to let
you create a "bare" function when you don't want to immediately pass it as a
block argument to some other method.
:::dart
var fn = new Fn {
IO.print("The body")
}
It is a runtime error if block is not a function.
arity
The number of arguments the function requires.
:::dart
IO.print(new Fn {}.arity) // 0.
IO.print(new Fn {|a, b, c| a }.arity) // 3.
call(args...)
TODO