This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,21 +1,22 @@
#define std'dictionary'*.
#define std'patterns'*.
#define system.
#symbol fibo : i =
#symbol fibo = &&:n
[
Control ifNot:(i < 0).
n < 0
? [ #throw InvalidArgumentException new:"Must be non negative". ].
#if (i < 2)
? [ ^ i. ]
| [ ^ fibo::(i - 2) + fibo::(i - 1). ].
^ &&:n [ (n > 1) ? [ ($self:(n - 2)) + ($self:(n - 1)) ] ! [ n ] ] : n.
].
#symbol Program =
#symbol program =
[
loop &&from:-1 &to:10 run: i =
control from:-1 &to:10 &do: &&:i
[
'program'output << "%nfib(" << i << ")=".
console << "%fib(" << i << ")=".
'program'output << fibo::i | << "failed".
console writeLine:(fibo:i) | onInvalidArgumentError: &&:e
[
console writeLine:"invalid".
].
].
].