예제 #1
0
func Get(env *Environment, sym *types.Symbol) (types.Type, error) {
	for e := env; e != nil; e = e.parent {
		for v := e.env; v != nil; {
			testSym, err := types.Caar(v)
			if err != nil {
				return nil, &envError{fmt.Sprintf("Checking for %s", sym.Value), err}
			}

			if types.Eqv(sym, testSym) {
				if r, err := types.Cdar(v); err != nil {
					return nil, &envError{fmt.Sprintf("Checking for %s", sym.Value), err}
				} else {
					return r, nil
				}
			}

			nextV, _ := types.Cdr(v)

			var ok bool
			v, ok = nextV.(*types.Pair)
			if !ok {
				return nil, &envError{m: "Corrupt environment!!!"}
			}
		}
	}

	return nil, &envError{m: fmt.Sprintf("Unknown variable: %s", sym.Value)}
}
예제 #2
0
func cdr(env interface{}, args t.Type) (t.Type, error) {
	return t.Cdar(args)
}