Keyed-Variables.html (4948B)
1 <html lang="en"> 2 <head> 3 <title>Keyed Variables - klisp Reference Manual</title> 4 <meta http-equiv="Content-Type" content="text/html"> 5 <meta name="description" content="klisp Reference Manual"> 6 <meta name="generator" content="makeinfo 4.13"> 7 <link title="Top" rel="start" href="index.html#Top"> 8 <link rel="prev" href="Promises.html#Promises" title="Promises"> 9 <link rel="next" href="Numbers.html#Numbers" title="Numbers"> 10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11 <meta http-equiv="Content-Style-Type" content="text/css"> 12 <style type="text/css"><!-- 13 pre.display { font-family:inherit } 14 pre.format { font-family:inherit } 15 pre.smalldisplay { font-family:inherit; font-size:smaller } 16 pre.smallformat { font-family:inherit; font-size:smaller } 17 pre.smallexample { font-size:smaller } 18 pre.smalllisp { font-size:smaller } 19 span.sc { font-variant:small-caps } 20 span.roman { font-family:serif; font-weight:normal; } 21 span.sansserif { font-family:sans-serif; font-weight:normal; } 22 --></style> 23 <link rel="stylesheet" type="text/css" href="css/style.css"> 24 </head> 25 <body> 26 <div class="node"> 27 <a name="Keyed-Variables"></a> 28 <p> 29 Next: <a rel="next" accesskey="n" href="Numbers.html#Numbers">Numbers</a>, 30 Previous: <a rel="previous" accesskey="p" href="Promises.html#Promises">Promises</a>, 31 Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 32 <hr> 33 </div> 34 35 <!-- node-name, next, previous, up --> 36 <h2 class="chapter">13 Keyed Variables</h2> 37 38 <p><a name="index-keyed-variables-161"></a> 39 A keyed variable is a device that associates a non-symbolic key (in 40 the form of an accessor applicative) with a value depending on the 41 context in which lookup occurs. Kernel provides two types of keyed 42 variables: dynamic & static. Keyed Dynamic Variables use the dynamic 43 extent as context and Keyed Static Variables use the dynamic 44 environment. 45 46 <h3 class="section">13.1 Keyed Dynamic Variables</h3> 47 48 <p><a name="index-keyed-dynamic-variables-162"></a><!-- add cf xref static --> 49 <!-- TODO add xref to dynamic extent --> 50 A keyed dynamic variable is a device that associates a non-symbolic 51 key (in the form of an accessor applicative) with a value depending on 52 the dynamic extent in which lookup occurs. 53 54 <div class="defun"> 55 — Applicative: <b>make-keyed-dynamic-variable</b> (<var>make-keyed-dynamic-variable</var>)<var><a name="index-make_002dkeyed_002ddynamic_002dvariable-163"></a></var><br> 56 <blockquote><p> Returns a list of the form <code>(b a)</code>, where <code>b</code> and <code>a</code> 57 are applicatives, as follows. Each call to 58 <code>make-keyed-dynamic-variable</code> returns different <code>b</code> and 59 <code>a</code>. 60 61 <ul> 62 <li><code>b</code> is an applicative that takes two arguments, the second of 63 which must be a combiner. It calls its second argument with no 64 operands (nil operand tree) in a fresh empty environment, and returns 65 the result. 66 67 <li><code>a</code> is an applicative that takes zero arguments. If the call to 68 <code>a</code> occurs within the dynamic extent of a call to <code>b</code>, then 69 <code>a</code> returns the value of the first argument passed to <code>b</code> in 70 the smallest enclosing dynamic extent of a call to <code>b</code>. If the 71 call to <code>a</code> is not within the dynamic extent of any call to 72 <code>b</code>, an error is signaled. 73 </ul> 74 </p></blockquote></div> 75 76 <h3 class="section">13.2 Keyed Static Variables</h3> 77 78 <p><a name="index-keyed-static-variables-164"></a> A keyed static variable is a device that binds data in an 79 environment by a non-symbolic key, where the key is an accessor 80 applicative. 81 <!-- add cf xref dynamic --> 82 83 <div class="defun"> 84 — Applicative: <b>make-keyed-static-variable</b> (<var>make-keyed-static-variable</var>)<var><a name="index-make_002dkeyed_002dstatic_002dvariable-165"></a></var><br> 85 <blockquote><p> Returns a list of the form <code>(b a)</code>, where <code>b</code> and <code>a</code> 86 are applicatives, as follows. Each call to <code>make-keyed-static-variable</code> 87 returns different <code>b</code> and <code>a</code>. 88 89 <ul> 90 <li><code>b</code> is an applicative that takes two arguments, the second of 91 which must be an environment. It constructs and returns a 92 child-environment of its second argument, with initially no local 93 bindings. 94 95 <li><code>a</code> is an applicative that takes zero arguments. If the dynamic 96 environment <code>e</code> of the call to a has an improper ancestor that 97 was constructed by a call to <code>b</code>, then a returns the value of the 98 first argument passed to <code>b</code> in the first such environment 99 encountered by a depth-first traversal of the improper ancestors of 100 <code>e</code>. If <code>e</code> has no improper ancestors constructed via 101 <code>b</code>, an error is signaled. 102 </ul> 103 </p></blockquote></div> 104 105 <!-- *-texinfo-*- --> 106 </body></html> 107