On Aug 2, 2014, Aditya Mahajan
wrote: On Sat, 2 Aug 2014, luigi scarso wrote:
On Sat, Aug 2, 2014, John Kitzmiller
wrote: Here is Lua code that prints the first nine fibonacci numbers: local function fib(n) f={1,1} ...the Wiki entries, CLD, and tried Aditya's method from Stack Exchange; I am missing something.
You have a *global* table f that collides with the internals of context ... local function fib(n) local f={1,1} ...
This version recomputes all fibnocci numbers from scrach each time. Here is a memoized version:
local fibs = {1, 1} local function fib(n) if fibs[n] == nil then print(">>>>", "Computing fib:" .. n) fibs[n] = fib(n-1) + fib(n-2) end ...
Thanks to you both! I missed the global/local conflict, and then learned a way to avoid double computation; thanks again! John