Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 5148

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>stashValue -- stash values of functions in their arguments</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_status.html">next</a> | <a href="_standard__Pairs.html">previous</a> | <a href="_status.html">forward</a> | <a href="_standard__Pairs.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<hr/>
<div><h1>stashValue -- stash values of functions in their arguments</h1>
<div class="single"><h2>Synopsis</h2>
<ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>((stashValue KEY) f) x</tt></div>
</dd></dl>
</div>
</li>
<li><div class="single">Inputs:<ul><li><span><tt>KEY</tt></span></li>
<li><span><tt>f</tt>, <span>a <a href="___Function.html">function</a></span></span></li>
<li><span><tt>x</tt>, <span>a <a href="___Mutable__Hash__Table.html">mutable hash table</a></span>, an argument for <tt>f</tt></span></li>
</ul>
</div>
</li>
<li><div class="single">Outputs:<ul><li><span>The value of <tt>f x</tt> is returned, but the value is saved in <tt>x#KEY</tt> and not recomputed later.  However, if the value found in <tt>x#KEY</tt> is <span>an <a href="___Cache__Function.html">a cache function</a></span>, such as is returned by <tt>(stashValue KEY) f</tt>, then the value of <tt>x#KEY x</tt> is returned instead, after first removing <tt>x#KEY</tt> from <tt>x</tt>.</span></li>
</ul>
</div>
</li>
</ul>
</div>
<div class="single"><h2>Description</h2>
<div><table class="examples"><tr><td><pre>i1 : x = new MutableHashTable from { val => 1000 }

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

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

o2 = f

o2 : FunctionClosure</pre>
</td></tr>
<tr><td><pre>i3 : h = (stashValue VALUE) f

o3 = {*a cache function*}

o3 : CacheFunction</pre>
</td></tr>
<tr><td><pre>i4 : h x
hi there

o4 = 1000000000000</pre>
</td></tr>
<tr><td><pre>i5 : h x

o5 = 1000000000000</pre>
</td></tr>
<tr><td><pre>i6 : peek x

o6 = MutableHashTable{val => 1000           }
                      VALUE => 1000000000000</pre>
</td></tr>
</table>
</div>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_cache__Value.html" title="cache values of functions in their arguments">cacheValue</a> -- cache values of functions in their arguments</span></li>
</ul>
</div>
<div class="waystouse"><div class="single"><h2>Code</h2>
<pre>../../m2/methods.m2:516:18-524: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))</pre>
</div>
</div>
</div>
</body>
</html>