diff options
| author | Tom Harley | 2019-10-12 02:41:50 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-10-12 02:41:50 +0100 |
| commit | 417c0addcafe8bfd3d9305ab7d2fac207ad54700 (patch) | |
| tree | f22954d08cdc910f4a2016323498f36a9b165a64 /simple.int | |
| parent | Implement function definitions (diff) | |
| download | sinter-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.int | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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]]] |
