Fixes for loops

This commit is contained in:
sloum 2022-07-02 20:13:30 -07:00
parent a48ec705be
commit 95b05e122f

View File

@ -209,7 +209,7 @@ func eval(exp expression, en *env) (value expression) {
break
}
test := testReturn[0]
var returnExpression expression = make([]expression, 0)
var returnExpression expression = []expression{symbol("list")}
if len(testReturn) > 1 {
returnExpression = testReturn[1]
}
@ -219,7 +219,7 @@ func eval(exp expression, en *env) (value expression) {
for {
// Check the condition by evaluating the test
if AnythingToBool(eval(test, newEnv)).(bool) {
if !AnythingToBool(eval(test, newEnv)).(bool) {
break
}
@ -230,10 +230,7 @@ func eval(exp expression, en *env) (value expression) {
eval(updates, newEnv)
}
fmt.Println("Return expression: ", returnExpression)
value = eval(returnExpression, newEnv)
fmt.Println("Evaluated return: ", value)
case "set!":
if len(e) < 3 {
value = exception("Invalid 'set!' syntax - too few arguments")