Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #27737
| Newsgroups | comp.lang.forth |
|---|---|
| Date | 2014-01-08 10:18 -0800 |
| References | <0c331663-8c0d-4b6d-9631-e2d7f4fc7e55@googlegroups.com> |
| Message-ID | <aa70e511-02c4-4e5d-bd5c-0dfdefc4cb2a@googlegroups.com> (permalink) |
| Subject | Re: Memoization |
| From | mhx@iae.nl |
On Wednesday, January 8, 2014 2:05:33 PM UTC+1, novembe...@gmail.com wrote:
> I was wondering how easy it would be to implement something like http://en.wikipedia.org/wiki/Memoization in forth.
[ skipping reams of code ]
> For small values it probably doesn't matter, but for larger values the speedup
> is worth it.
CREATE _fib HERE #47 CELLS ALLOT
: fib ( n1 -- n2 ) RECURSIVE
dup 2 < IF drop 1 exit THEN
dup _fib swap cells + @ DUP IF NIP EXIT ELSE DROP THEN
dup >R
dup 1- fib
swap 2- fib +
DUP _fib R> cells + ! ;
-marcel
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
Memoization november.nihal@gmail.com - 2014-01-08 05:05 -0800 Re: Memoization mhx@iae.nl - 2014-01-08 10:18 -0800
csiph-web