Control.html (7410B)
1 <html lang="en"> 2 <head> 3 <title>Control - 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="Symbols.html#Symbols" title="Symbols"> 9 <link rel="next" href="Pairs-and-lists.html#Pairs-and-lists" title="Pairs and lists"> 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="Control"></a> 28 <p> 29 Next: <a rel="next" accesskey="n" href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a>, 30 Previous: <a rel="previous" accesskey="p" href="Symbols.html#Symbols">Symbols</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">6 Control</h2> 37 38 <p><a name="index-control-27"></a><a name="index-inert-28"></a> The inert data type is provided for use with control combiners. It 39 consists of a single immutable value, having external representation 40 <code>#inert</code>. The inert type is encapsulated. 41 42 <div class="defun"> 43 — Applicative: <b>inert?</b> (<var>inert? . objects</var>)<var><a name="index-inert_003f-29"></a></var><br> 44 <blockquote><p> The primitive type predicate for type inert. <code>inert?</code> 45 returns true iff all the objects in <code>objects</code> are of type inert. 46 </p></blockquote></div> 47 48 <div class="defun"> 49 — Operative: <b>$if</b> (<var>$if <test> <consequent> <alternative></var>)<var><a name="index-g_t_0024if-30"></a></var><br> 50 <blockquote><p> The <code>$if</code> operative first evaluates <code><test></code> in the 51 dynamic environment. If the result is not of type boolean, an error 52 is signaled. If the result is true, <code><consequent></code> is then 53 <!-- TODO add xref to tail context --> 54 evaluated in the dynamic environment as a tail context. Otherwise, 55 <code><alternative></code> is evaluated in the dynamic environment as a tail 56 context. 57 </p></blockquote></div> 58 59 <div class="defun"> 60 — Operative: <b>$sequence</b> (<var>$sequence . <objects></var>)<var><a name="index-g_t_0024sequence-31"></a></var><br> 61 <blockquote><p>The <code>$sequence</code> operative evaluates the elements of the list 62 <code><objects></code> in the dynamic environment, one at a time from left 63 to right. If <code><objects></code> is a cyclic list, element evaluation 64 continues indefinitely, with elements in the cycle being evaluated 65 repeatedly. If <code><objects></code> is a nonempty finite list, its last 66 <!-- TODO add xref for tail context. --> 67 element is evaluated as a tail context. If <code><objects></code> is the 68 empty list, the result is inert. 69 </p></blockquote></div> 70 71 <div class="defun"> 72 — Operative: <b>$cond</b> (<var>$cond . <clauses></var>)<var><a name="index-g_t_0024cond-32"></a></var><br> 73 <blockquote><p><code><clauses></code> should be a list of clause expressions, each of the 74 form <code>(<test> . <body>)</code>, where body is a list of expressions. 75 76 <p>The following equivalences define 77 the behaviour of the <code>$cond</code> operative: 78 <pre class="example"> ($cond) == #inert 79 ($cond (<test> . <body>) . <clauses>) == 80 ($if <test> ($sequence . <body>) ($cond . <clauses>)) 81 </pre> 82 </blockquote></div> 83 84 <div class="defun"> 85 — Applicative: <b>for-each</b> (<var>for-each applicative . lists</var>)<var><a name="index-for_002deach-33"></a></var><br> 86 <blockquote><p><code>lists</code> must be a nonempty list of lists; if there are two or 87 more, they should all be the same length. If lists is empty, or if all 88 of its elements are not lists of the same length, an error is 89 signaled. 90 91 <!-- TODO add xref to map --> 92 <p><code>for-each</code> behaves identically to <code>map</code>, except that instead 93 of accumulating and returning a list of the results of the 94 element-wise applications, the results of the applications are 95 discarded and the result returned by <code>for-each</code> is inert. 96 </p></blockquote></div> 97 98 <div class="defun"> 99 — Applicative: <b>string-for-each</b> (<var>string-for-each applicative . strings</var>)<var><a name="index-string_002dfor_002deach-34"></a></var><br> 100 — Applicative: <b>vector-for-each</b> (<var>vector-for-each applicative. vectors</var>)<var><a name="index-vector_002dfor_002deach-35"></a></var><br> 101 — Applicative: <b>bytevector-for-each</b> (<var>bytevector-for-each applicative . bytevectors</var>)<var><a name="index-bytevector_002dfor_002deach-36"></a></var><br> 102 <blockquote><p><code>strings</code>, <code>vectors</code>, or <code>bytevectors</code> should be 103 non-empty lists of the corresponding type and all elements should be 104 of the same length. 105 106 <p>These applicatives behave as <code>for-each</code> except that the list of 107 elements passed to <code>applicative</code> are the n-th chars, objects, or 108 uint8s of the strings, vectors or bytevectors passed as arguments. 109 110 <p>SOURCE NOTE: These are taken from r7rs. 111 </p></blockquote></div> 112 113 <div class="defun"> 114 — Operative: <b>$when</b> (<var>$when <test> . <body></var>)<var><a name="index-g_t_0024when-37"></a></var><br> 115 — Operative: <b>$unless</b> (<var>$unless <test> . <body></var>)<var><a name="index-g_t_0024unless-38"></a></var><br> 116 <blockquote><p><code>body</code> should be a list of expressions. 117 118 <p>These operatives behave as one-armed <code>$if</code>s with an implicit 119 <code>$sequence</code>, except that they always discard the last value and 120 the result returned is inert. 121 122 <p>So both <code>$when</code>, and <code>$unless</code> evaluate <code><test></code> in the 123 dynamic environment. If the result is non boolean an error is 124 signaled. In <code>$when</code> if the result is false and in 125 <code>$unless</code> if the result is true, the expressions in <code><body></code> 126 are not evaluated and an inert value is returned. Otherwise, the 127 expressions in <code><body></code> are evaluated sequentially in the dynamic 128 environment. If <code><body></code> is a non cyclic list, the last 129 expression in <code><body></code> is evaluated in a special type of tail 130 context, that, upon receiving a value discards it and returns an inert 131 value instead. If <code><body></code> is a cyclic list, element evaluation 132 continues indefinitely, with elements in the cycle being evaluated 133 repeatedly. 134 <!-- TODO xref tail-context --> 135 SOURCE NOTE: These are taken from r7rs. 136 </p></blockquote></div> 137 138 <!-- *-texinfo-*- --> 139 </body></html> 140