lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 5 Mar 2002 at 20:55, Peter Prade wrote:

> it should be easy to setup tag-methods for that, so that you can write:
> 
> fib[0] = 1
> fib[1] = 1
> fib.fn = function(n) return fib[n-1]+fib[n-2] end
> 
> now you only need to set tagmethods so that every time a value is not found
> in the table, it is generated from the "fn" function entry.

I'm farily certain it will be a bother if the function is multi-variate. F.ex:
function foo(x,0) return 1 end
function foo(x,1) return x end
function foo(1,x) return 1 end
function foo(x,y) return somethingHideouslyExpensiveToCompute end

Or if one allows ranges, relational operators or even functions.

MvH Dan Andersson