next | previous | forward | backward | up | top | index | toc | home

cacheValue -- cache values of functions in their arguments

Synopsis

Description

i1 : x = new HashTable from { val => 1000, cache => new CacheTable }

o1 = HashTable{cache => CacheTable{}}
               val => 1000

o1 : HashTable
i2 : f = (t -> (print "hi there"; t.val^4))

o2 = f

o2 : FunctionClosure
i3 : h = (cacheValue VALUE) f

o3 = h

o3 : FunctionClosure
i4 : h x
hi there

o4 = 1000000000000
i5 : h x

o5 = 1000000000000
i6 : peek'_2 x

o6 = HashTable{cache => CacheTable{VALUE => 1000000000000}}
               val => 1000

See also

Code

-- ../../../../Macaulay2/m2/methods.m2:449-451
cacheValue = key -> f -> x -> (
     c := x.cache;
     if c#?key then c#key else c#key = f x)