bind expression (:=) instead of let
Some checks failed
Build / build (push) Successful in 10m26s
Test / build (push) Failing after 16m44s

This commit is contained in:
Chuck Smith
2024-03-21 17:43:03 -04:00
parent 66d5453ecc
commit 6282075e66
36 changed files with 425 additions and 583 deletions

View File

@@ -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)