reading symbols from environments
parent
b6a88a15fb
commit
7eedbb4e92
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UnknownSymbolError struct{ symbol }
|
||||
|
||||
func (u UnknownSymbolError) Error() string {
|
||||
return fmt.Sprintf(`unknown symbol "%v"`, u.symbol)
|
||||
}
|
||||
|
||||
type environment map[symbol]interface{}
|
||||
|
||||
func (e environment) get(key symbol) (interface{}, error) {
|
||||
v, ok := e[key]
|
||||
if ok {
|
||||
return v, nil
|
||||
}
|
||||
return nil, UnknownSymbolError{key}
|
||||
}
|
Loading…
Reference in New Issue