Documentation
¶
Overview ¶
Package meowrt provides the runtime support for compiled Meow programs. It defines the dynamic Value interface and concrete types used for all values at runtime, along with built-in functions and operators.
Value Types ¶
Every Meow value implements the Value interface:
- Int integer (int64)
- Float floating-point (float64)
- String string
- Bool boolean
- NilValue nil / catnap
- Func callable function
- List ordered collection of values
- Furball error value (caught by Gag)
Constructors ¶
- NewInt creates an Int
- NewFloat creates a Float
- NewString creates a String
- NewBool creates a Bool
- NewNil creates a NilValue
- NewFunc creates a Func
- NewList creates a List
Built-in Functions ¶
- Nya print values to stdout (like fmt.Println)
- Hiss raise an error with a message
- Gag call a function and recover from panics (returns Furball on error)
- GagOr call a function and return a fallback on panic (~> operator)
- IsFurball check if a value is a Furball
- Call invoke a Func value
- Len return the length of a String or List
- ToInt convert to Int
- ToFloat convert to Float
- ToString convert to String
List Higher-Order Functions ¶
- Lick map a function over a list
- Picky filter a list by predicate
- Curl reduce (fold) a list
- Append append a value to a list (returns new list)
- Head return the first element
- Tail return all elements except the first
Operators ¶
- Arithmetic: Add, Sub, Mul, Div, Mod, Negate
- Equality: Equal, NotEqual
- Comparison: LessThan, GreaterThan, LessEqual, GreaterEqual
- Logical: And, Or, Not
Pattern Matching ¶
- MatchValue check if two values are equal
- MatchRange check if a value is within an integer range [low, high]
Index ¶
- func AsBool(v Value) bool
- func AsFloat(v Value) float64
- func AsInt(v Value) int64
- func AsString(v Value) string
- func ClearMethods()
- func LookupMethod(typeName, methodName string) (func(...Value) Value, bool)
- func MatchRange(v Value, low, high int64) bool
- func MatchValue(v, pattern Value) bool
- func RegisterMethod(typeName, methodName string, fn func(...Value) Value)
- func ToJSON(v Value) string
- type Bool
- type Float
- type Func
- type Furball
- type Int
- type Kitty
- type List
- type Map
- type NilValue
- type String
- type Value
- func Add(a, b Value) Value
- func And(a, b Value) Value
- func Append(lst Value, v Value) Value
- func Call(fn Value, args ...Value) Value
- func Curl(lst Value, init Value, fn Value) Value
- func DispatchMethod(obj Value, methodName string, args ...Value) Value
- func Div(a, b Value) Value
- func Equal(a, b Value) Value
- func Gag(fn Value) Value
- func GagOr(fn Value, fallback Value) Value
- func GreaterEqual(a, b Value) Value
- func GreaterThan(a, b Value) Value
- func Head(lst Value) Value
- func Hiss(args ...Value) Value
- func IsFurball(v Value) Value
- func Len(v Value) Value
- func LessEqual(a, b Value) Value
- func LessThan(a, b Value) Value
- func Lick(lst Value, fn Value) Value
- func Mod(a, b Value) Value
- func Mul(a, b Value) Value
- func Negate(v Value) Value
- func Not(v Value) Value
- func NotEqual(a, b Value) Value
- func Nya(args ...Value) Value
- func Or(a, b Value) Value
- func Picky(lst Value, fn Value) Value
- func Sub(a, b Value) Value
- func Tail(lst Value) Value
- func ToFloat(v Value) Value
- func ToInt(v Value) Value
- func ToString(v Value) Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsBool ¶ added in v0.2.0
AsBool extracts a bool from a Value, panicking with a descriptive message on type mismatch.
func AsFloat ¶ added in v0.2.0
AsFloat extracts a float64 from a Value, panicking with a descriptive message on type mismatch.
func AsInt ¶ added in v0.2.0
AsInt extracts an int64 from a Value, panicking with a descriptive message on type mismatch.
func AsString ¶ added in v0.2.0
AsString extracts a string from a Value, panicking with a descriptive message on type mismatch.
func ClearMethods ¶ added in v0.2.0
func ClearMethods()
ClearMethods removes all registered methods from the registry.
func LookupMethod ¶ added in v0.2.0
LookupMethod returns the method function for a type, if registered.
func MatchRange ¶
MatchRange checks if a value is within an integer range [low, high].
func RegisterMethod ¶ added in v0.2.0
RegisterMethod registers a method for a named type.
Types ¶
type Func ¶
type Func struct {
// Name is the function name for display purposes.
Name string
// Fn is the underlying Go function implementation.
Fn func(args ...Value) Value
// Arity is the number of expected arguments. -1 means variadic (no currying).
Arity int
}
Func represents a function value.
func NewFunc ¶
NewFunc creates a new Func value with the given name and implementation. The function is variadic (Arity -1) and will not be auto-curried. fn must not be nil; passing nil will panic.
func NewFuncWithArity ¶ added in v0.2.0
NewFuncWithArity creates a new Func value with a fixed arity. When called with fewer arguments than arity, the function is automatically partially applied (curried).
func PartialApply ¶ added in v0.2.0
PartialApply creates a new function that captures the given arguments and waits for the remaining ones. The returned function's arity is reduced by the number of supplied arguments.
type Furball ¶
type Furball struct{ Message string }
Furball represents an error value caught by Gag.
type Kitty ¶ added in v0.2.0
Kitty represents a user-defined struct value.
func NewKitty ¶ added in v0.2.0
NewKitty creates a new Kitty value. Panics if argument count does not match field count.
type List ¶
type List struct {
// Items is the slice of values in the list.
Items []Value
}
List represents a list value.
type Map ¶ added in v0.2.0
Map represents a map value with string keys.
type Value ¶
Value is the core interface for all Meow values.
func Add ¶
Add performs addition on same-type operands only. int+int→int, float+float→float, string+string→string.
func Call ¶
Call invokes a function value with the given arguments. If the function has a fixed arity and fewer arguments are supplied, it returns a partially applied function.
func DispatchMethod ¶ added in v0.2.0
DispatchMethod calls a method on a value by looking up the method registry.
func Gag ¶
Gag calls fn (a zero-argument Func) and recovers from any panic, returning the panic message wrapped in a Furball. If fn succeeds, its return value is returned as-is.
func GagOr ¶
GagOr calls fn (a zero-argument Func) and recovers from any panic. If the call succeeds, its return value is returned as-is. If it panics, the fallback is used: if fallback is a Func it is called with the Furball as argument; otherwise fallback is returned directly.
func GreaterEqual ¶
GreaterEqual performs greater-than-or-equal comparison on same-type operands only.
func GreaterThan ¶
GreaterThan performs greater-than comparison on same-type operands only.