Skip to content

Function Prototypes

Functions also have prototypes.

Function prototypes expose metadata and allow initialized calls.

fn add(a: int, b: int) int {
return a + b
}
println(add.__args__)
println(add.__returns__)

Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.

NameTypeDescription
__args__[]dict[string, any]Function argument metadata.
__returns__string | []stringReturn type metadata.

Each item in __args__ contains:

KeyDescription
nameArgument name.
typeArgument type as a string or list of strings for union types.
defaultDefault value, or nil.
MethodReturnsDescription
init(...args)fn() -> RCaptures arguments and returns an initialized zero-argument function.
call(...args)RCalls the function, but should be used only from an initialized function context.
fn greet(name: string) string {
return "Hello, " + name
}
println(greet.__args__)
println(greet.__returns__)
fn greet(name: string) string {
return "Hello, " + name
}
let martin = greet.init("Martin")
println(martin())

The lower-level call method expects an initialized function context, so direct use can error.

fn greet(name: string) string {
return "Hello, " + name
}
// Prefer init for normal usage:
let ready = greet.init("Nubo")
println(ready())