mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
UG updates from notes.
This commit is contained in:
parent
d2a35d3ca7
commit
01d8f31fb3
2 changed files with 27 additions and 0 deletions
Binary file not shown.
27
docs/snippets/fibonacci.foorth
Normal file
27
docs/snippets/fibonacci.foorth
Normal file
|
@ -0,0 +1,27 @@
|
|||
// A Fibonacci sequencer class.
|
||||
// - Instance variables
|
||||
|
||||
class: Fibonacci
|
||||
|
||||
(Fibonacci .new a_fibonacci)
|
||||
Fibonacci .: .init 1 var@: @a 1 var@: @b ;
|
||||
|
||||
(a_fibonacci .next a_value)
|
||||
Fibonacci .: .next @a @ dup @b @ swap over + @b ! @a ! ;
|
||||
|
||||
(a_value a_value a_fibonacci .reset -)
|
||||
Fibonacci .: .reset @b ! @a ! ;
|
||||
|
||||
//Create a generator and save its value.
|
||||
Fibonacci .new val$: $fib
|
||||
|
||||
//Create a testing word for the generator.
|
||||
: run_test 0 12 do $fib .next . space loop cr ;
|
||||
|
||||
."Classical Fibonacci Sequence:" cr
|
||||
run_test
|
||||
|
||||
0.5 0.5 $fib .reset
|
||||
|
||||
."Modified Fibonacci Sequence:" cr
|
||||
run_test
|
Loading…
Reference in a new issue