next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc :: stashValue

stashValue -- stash values of functions in their arguments

Synopsis

Description

i1 : x = new MutableHashTable from { val => 1000 }

o1 = MutableHashTable{...1...}

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

o2 = f

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

o3 = -*a cache function*-

o3 : CacheFunction
i4 : h x
hi there

o4 = 1000000000000
i5 : h x

o5 = 1000000000000
i6 : peek x

o6 = MutableHashTable{val => 1000           }
                      VALUE => 1000000000000

Code

../../../../../../../Macaulay2/m2/methods.m2:602:18-610:26: --source code:
stashValue = key -> f -> new CacheFunction from (x -> (
          if x#?key then (
               val := x#key;
               if class val === CacheFunction then (
                    remove(x,key);
                    x#key = val x)
               else val
               )
          else x#key = f x))

See also

For the programmer

The object stashValue is a function closure.