Add the 'do' special form

This commit is contained in:
Sameer Rahmani 2020-11-25 16:18:38 +00:00
parent c2326ae546
commit 0ef38cd9bd
1 changed files with 12 additions and 0 deletions

View File

@ -161,10 +161,22 @@ tco:
ret, err = Fn(rt, scope, list.Rest().(*List))
break tco // return
// `if` evaluation rules:
// * It has to get only 3 arguments: PRED THEN ELSE
// * Evaluate only the PRED expression if the result
// is not `nil` or `false` evaluates THEN otherwise
// evaluate the ELSE expression and return the result.
case "if":
ret, err = If(rt, scope, list.Rest().(*List))
break tco // return
// `do` evaluation rules:
// * Evaluate the body as a new block in the TCO loop
// and return the result of the last expression
case "do":
expressions = MakeBlock(list.Rest().(*List).ToSlice())
continue tco // Loop over to execute the new expressions
// list evaluation rules:
// * The first element of the list has to be an expression which is callable
// * An empty list evaluates to itself.