[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Weak tuples (was Re: upvalues and ...)
- From: Mark Hamburg <mhamburg@...>
- Date: Sat, 21 Aug 2004 15:44:49 -0700
on 8/21/04 1:14 PM, Wim Couwenberg at debosberg@yahoo.com wrote:
> PS (unrelated): Can anyone show a sensible example
> where you'd like to use a weak-valued immutable tuple?
function makeCaching( func )
local cache = {}
return function( ... )
local t = unique_immutable_tuple( ... )
local result = cache[ t ]
if not result then
result = unique_immutable_tuple( func( ... ) )
cache[ t ] = result
end
return unpack_tuple( result )
end
end
The problem with this approach is that it makes all arguments and results
persistent. Both weak arguments and weak results can be interesting in some
cases.
Mark