government / eval / error.go

@ 5679446275e9c90525ed7267e7f42f633296e7a1 | 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...)}
}