stdlib

package
v0.84.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompiledFunc

type CompiledFunc struct {
	// contains filtered or unexported fields
}

CompiledFunc is a Function paired with its parameter signature precomputed once at registration. Argument resolution reads the cached signature instead of recomputing it, so nothing about the (static) parameter list is derived per call.

func (*CompiledFunc) Call

func (c *CompiledFunc) Call(args map[string]core.Value) (core.Value, error)

func (*CompiledFunc) Name

func (c *CompiledFunc) Name() string

func (*CompiledFunc) Params

func (c *CompiledFunc) Params() []Parameter

func (*CompiledFunc) Resolve

func (c *CompiledFunc) Resolve(
	positional []core.Value,
	named map[string]core.Value,
) (map[string]core.Value, error)

Resolve binds evaluated call arguments to the function's parameters and returns them keyed by parameter name.

Binding is strict (Python keyword-only style): positional arguments fill positional parameters by position, named arguments fill named parameters by name. A positional parameter cannot be supplied by name, and a named parameter cannot be supplied positionally.

type Function

type Function interface {
	// Returns the function name as it appears in source code.
	Name() string

	// Returns the ordered list of parameter descriptors.
	// Order matters for positional argument binding.
	Params() []Parameter

	// Call executes the function with fully-resolved, validated arguments.
	// args is keyed by parameter name and always contains every parameter
	// (required args + provided optional args + defaults).
	Call(args map[string]core.Value) (core.Value, error)
}

Function is the interface every built-in function must implement.

Lifecycle during a call:

  1. Interpreter evaluates all argument expressions -> positional []Value + named map[string]Value
  2. CompiledFunc.Resolve validates and maps them to the parameter list -> map[string]Value
  3. Function.Call receives the resolved map and returns a Value

type Parameter

type Parameter struct {
	// Name is the parameter name. For named parameters it is the keyword used
	// at the call site: fn(name: value). For positional parameters it is used
	// as the key in the resolved argument map.
	Name string

	// Description documents the parameter for help output and generated docs.
	Description string

	// Default is the value substituted when a named parameter is omitted.
	// Its presence is what makes a parameter named (keyword-only) and optional;
	// a nil Default makes the parameter positional and required.
	Default core.Value

	// AcceptedKinds lists the value kinds this parameter accepts.
	// An empty slice means any kind is accepted.
	AcceptedKinds []core.ValueKind
}

Describes a single parameter of a built-in function.

Whether a parameter is positional or named is derived from Default, mirroring the Python/PHP model:

  • Positional (Default == nil): supplied by position - fn(value) - always required.
  • Named (Default != nil): supplied by name - fn(name: value) - always optional, falling back to Default when omitted.

All positional parameters must be declared before any named parameter.

func (Parameter) Named

func (p Parameter) Named() bool

Named reports whether the parameter is keyword-only (bound by name).

func (Parameter) Required

func (p Parameter) Required() bool

Required reports whether the parameter must be supplied by the caller. Positional parameters are always required; named parameters never are.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all built-in functions available during program execution. It is built once at startup and shared across all Program.Run calls.

func GetRegistry

func GetRegistry() *Registry

func (*Registry) Get

func (r *Registry) Get(name string) (*CompiledFunc, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL