felise/test.fe

37 lines
546 B
Plaintext

proc fib
| Stack: INT
Read :
Push : INT
Notes: Calculates the nth fibonacci number where n is an INT on TOS at call time |
svar! fib#
INT var! a
1 svar! b
INT var! s
proc continue-loop? fib# 0 > end
continue-loop? while
a b + set! s
b set! a
s set! b
fib# 1 - set! fib#
continue-loop?
end
a
end
# run it!
sys-args length 0 > if
try
# attempt to convert to INT
sys-args 1 <- INT cast
catch
"Requires an integer" throw
end
fib println
else
"No input\n" stderr file-write
end