lua-users home
lua-l archive

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


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