government / eval / error.go

@ 0fff601606926403bf0266dd4ab33726a7814f2d | history


package eval

import "fmt"

// Error codes. Step 1.13 adds source locations; the codes are stable.
const (
	ErrUnbound      = "E-UNBOUND"
	ErrSyntax       = "E-SYNTAX"
	ErrSpecialForm  = "E-SPECIAL-FORM"
	ErrNotAFunction = "E-NOT-A-FUNCTION"
	ErrArity        = "E-ARITY"
	ErrType         = "E-TYPE"
	ErrArith        = "E-ARITH"
	ErrImmutable    = "E-IMMUTABLE"
)

type Error struct {
	Code string
	Msg  string
}

func (e *Error) Error() string { return e.Code + ": " + e.Msg }

func errorf(code, format string, args ...any) *Error {
	return &Error{Code: code, Msg: fmt.Sprintf(format, args...)}
}