bind expression (:=) instead of let
This commit is contained in:
@@ -45,6 +45,23 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
|
||||
}
|
||||
return &object.ReturnValue{Value: val}
|
||||
|
||||
case *ast.BindExpression:
|
||||
value := Eval(node.Value, env)
|
||||
if isError(value) {
|
||||
return value
|
||||
}
|
||||
|
||||
if ident, ok := node.Left.(*ast.Identifier); ok {
|
||||
if immutable, ok := value.(object.Immutable); ok {
|
||||
env.Set(ident.Value, immutable.Clone())
|
||||
} else {
|
||||
env.Set(ident.Value, value)
|
||||
}
|
||||
|
||||
return NULL
|
||||
}
|
||||
return newError("expected identifier on left got=%T", node.Left)
|
||||
|
||||
case *ast.AssignmentExpression:
|
||||
left := Eval(node.Left, env)
|
||||
if isError(left) {
|
||||
@@ -94,18 +111,6 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
|
||||
|
||||
return NULL
|
||||
|
||||
case *ast.LetStatement:
|
||||
val := Eval(node.Value, env)
|
||||
if isError(val) {
|
||||
return val
|
||||
}
|
||||
|
||||
if immutable, ok := val.(object.Immutable); ok {
|
||||
env.Set(node.Name.Value, immutable.Clone())
|
||||
} else {
|
||||
env.Set(node.Name.Value, val)
|
||||
}
|
||||
|
||||
case *ast.Identifier:
|
||||
return evalIdentifier(node, env)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user