From 0ef38cd9bd1eaf401fea24f6bb3cbde40124b87c Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Wed, 25 Nov 2020 16:18:38 +0000 Subject: [PATCH] Add the 'do' special form --- bootstrap/pkg/core/eval.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bootstrap/pkg/core/eval.go b/bootstrap/pkg/core/eval.go index df23791..2400a43 100644 --- a/bootstrap/pkg/core/eval.go +++ b/bootstrap/pkg/core/eval.go @@ -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.