From 417c0addcafe8bfd3d9305ab7d2fac207ad54700 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 12 Oct 2019 02:41:50 +0100 Subject: Implement recursive definition support Enables definition of a recursive function through defining a base case using an `if` statement. Previously, doing this would produce compilable code, but running the product executable would cause a stack overflow, since the executable would attempt to evaluate both sides of the branch. Making the `if` statement a built-in part of the language is a bit crude, but is simple and works. Maybe, if time allows, this will be revisited. --- simple.int | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'simple.int') diff --git a/simple.int b/simple.int index ad6d789..fe34eab 100644 --- a/simple.int +++ b/simple.int @@ -1,2 +1,3 @@ +[def (INT fact) [(INT n)] [if n [* n [fact [- n 1]]] 1]] [def (INT double) [(INT x)] [* 2 x]] -[def (INT main) [] [debug_int [+ 3 [double 4]]]] +[def (INT main) [] [debug_int [fact 10]]] -- cgit v1.2.1