Update README, new tests
This commit is contained in:
@@ -76,12 +76,12 @@ build
|
|||||||
- [x] Maths
|
- [x] Maths
|
||||||
- [x] Comparisions
|
- [x] Comparisions
|
||||||
- [ ] Type conversions
|
- [ ] Type conversions
|
||||||
- [ ] Functions
|
- [x] Functions
|
||||||
- [x] Define functions
|
- [x] Define functions
|
||||||
- [x] Call functions
|
- [x] Call functions
|
||||||
- [ ] Return values (type checked)
|
- [x] Return values (type checked)
|
||||||
- [ ] Arguments for functions
|
- [x] Arguments for functions
|
||||||
- [ ] Jumping within functions
|
- [x] Jumping within functions
|
||||||
- [ ] Custom data structures
|
- [ ] Custom data structures
|
||||||
- [ ] Working with external libraries
|
- [ ] Working with external libraries
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,18 @@ fun !dingus -string
|
|||||||
return "dingle"
|
return "dingle"
|
||||||
endfun
|
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
|
call !dingus &e
|
||||||
println $e
|
println $e
|
||||||
|
|
||||||
|
call !jumpy &x
|
||||||
|
|||||||
24
tests/recursivefib.grnd
Normal file
24
tests/recursivefib.grnd
Normal 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
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
fun !dingle -int -function &in
|
fun !dingle -int -function &in -int &counter
|
||||||
call !in &tmp
|
add 1 $counter &counter
|
||||||
|
println "We are" $counter "iterations deep"
|
||||||
|
call !in $in $counter &out
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
call !dingle $dingle 0 &out
|
||||||
|
|||||||
Reference in New Issue
Block a user