summaryrefslogtreecommitdiff
path: root/simple.int
diff options
context:
space:
mode:
authorTom Harley2019-10-12 02:41:50 +0100
committerTom Harley2019-10-12 02:41:50 +0100
commit417c0addcafe8bfd3d9305ab7d2fac207ad54700 (patch)
treef22954d08cdc910f4a2016323498f36a9b165a64 /simple.int
parentImplement function definitions (diff)
downloadsinter-417c0addcafe8bfd3d9305ab7d2fac207ad54700.tar.gz
sinter-417c0addcafe8bfd3d9305ab7d2fac207ad54700.zip

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.

Diffstat (limited to 'simple.int')
-rw-r--r--simple.int3
1 files changed, 2 insertions, 1 deletions
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]]]