Files
wren/doc/site/core/fn.markdown
T
Bob Nystrom b7904a89c9 feat: add String.fromCodePoint static method and refactor UTF-8 encoding into reusable utilities
Implement the `String.fromCodePoint(_)` primitive that creates a string from a Unicode code point, with validation for integer range 0–0x10ffff. Extract inline UTF-8 encoding logic from `readUnicodeEscape` in the compiler into new `wrenUtf8NumBytes` and `wrenUtf8Encode` utility functions in `wren_utils`, and add `wrenStringFromCodePoint` helper in `wren_value`. Update documentation for core classes to add "Methods" and "Static Methods" section headers, and include `String.fromCodePoint` docs with example. Add a test file `from_code_point.wren` covering various code points.
2015-03-27 14:43:36 +00:00

838 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 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 function is not a function.

Methods

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