Update README, new tests

This commit is contained in:
2025-12-11 14:24:11 +11:00
parent 4c6aa97fd5
commit 633e438712
4 changed files with 47 additions and 6 deletions

View File

@@ -2,5 +2,18 @@ fun !dingus -string
return "dingle"
endfun
fun !jumpy
set &x 0
@loop
equal $x 10 &cond
if $cond %endloop
add 1 $x &x
println $x
jump %loop
@endloop
endfun
call !dingus &e
println $e
call !jumpy &x

24
tests/recursivefib.grnd Normal file
View File

@@ -0,0 +1,24 @@
fun !fib -int -int &n -function &fib
# Base case: fib(0) = 0, fib(1) = 1
lesser $n 2 &isBase
if $isBase %baseCase
# Recursive case: fib(n) = fib(n-1) + fib(n-2)
subtract $n 1 &nMinus1
call !fib $nMinus1 $fib &fib1
subtract $n 2 &nMinus2
call !fib $nMinus2 $fib &fib2
add $fib1 $fib2 &result
return $result
@baseCase
return $n
endfun
# Main program
println "Computing fib(30) recursively..."
call !fib 30 $fib &answer
println "Result:" $answer
end

View File

@@ -1,3 +1,7 @@
fun !dingle -int -function &in
call !in &tmp
fun !dingle -int -function &in -int &counter
add 1 $counter &counter
println "We are" $counter "iterations deep"
call !in $in $counter &out
endfun
call !dingle $dingle 0 &out