32 lines
534 B
Go
32 lines
534 B
Go
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
|
|
var namespaces = make(map[string]env)
|
|
var altnamespaces = make(map[string]string)
|