slope/environment.go

32 lines
534 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
)
type vars map[symbol]expression
type env struct {
vars
outer *env
}
func (e *env) Find(s symbol) (*env, error) {
if _, ok := e.vars[s]; ok {
return e, nil
} else if e.outer == nil {
if panicOnException {
panic(fmt.Sprintf("Symbol %q is not defined", s))
} else {
return nil, fmt.Errorf("Symbol %q is not defined", s)
}
} else {
en, err := e.outer.Find(s)
return en, err
}
}
var globalenv env
2022-06-16 21:04:13 +00:00
var namespaces = make(map[string]env)
2022-06-16 21:48:53 +00:00
var altnamespaces = make(map[string]string)