klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

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:&nbsp;<a rel="next" accesskey="n" href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a>,
     30 Previous:&nbsp;<a rel="previous" accesskey="p" href="Symbols.html#Symbols">Symbols</a>,
     31 Up:&nbsp;<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 &mdash; 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 &mdash; Operative: <b>$if</b> (<var>$if &lt;test&gt; &lt;consequent&gt; &lt;alternative&gt;</var>)<var><a name="index-g_t_0024if-30"></a></var><br>
     50 <blockquote><p>  The <code>$if</code> operative first evaluates <code>&lt;test&gt;</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>&lt;consequent&gt;</code> is then
     53 <!-- TODO add xref to tail context -->
     54 evaluated in the dynamic environment as a tail context.  Otherwise,
     55 <code>&lt;alternative&gt;</code> is evaluated in the dynamic environment as a tail
     56 context. 
     57 </p></blockquote></div>
     58 
     59 <div class="defun">
     60 &mdash; Operative: <b>$sequence</b> (<var>$sequence . &lt;objects&gt;</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>&lt;objects&gt;</code> in the dynamic environment, one at a time from left
     63 to right.  If <code>&lt;objects&gt;</code> is a cyclic list, element evaluation
     64 continues indefinitely, with elements in the cycle being evaluated
     65 repeatedly.  If <code>&lt;objects&gt;</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>&lt;objects&gt;</code> is the
     68 empty list, the result is inert. 
     69 </p></blockquote></div>
     70 
     71 <div class="defun">
     72 &mdash; Operative: <b>$cond</b> (<var>$cond . &lt;clauses&gt;</var>)<var><a name="index-g_t_0024cond-32"></a></var><br>
     73 <blockquote><p><code>&lt;clauses&gt;</code> should be a list of clause expressions, each of the
     74 form <code>(&lt;test&gt; . &lt;body&gt;)</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 (&lt;test&gt; . &lt;body&gt;) . &lt;clauses&gt;) ==
     80             ($if &lt;test&gt; ($sequence . &lt;body&gt;) ($cond . &lt;clauses&gt;))
     81 </pre>
     82         </blockquote></div>
     83 
     84 <div class="defun">
     85 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; Operative: <b>$when</b> (<var>$when &lt;test&gt; . &lt;body&gt;</var>)<var><a name="index-g_t_0024when-37"></a></var><br>
    115 &mdash; Operative: <b>$unless</b> (<var>$unless &lt;test&gt; . &lt;body&gt;</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>&lt;test&gt;</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>&lt;body&gt;</code>
    126 are not evaluated and an inert value is returned.  Otherwise, the
    127 expressions in <code>&lt;body&gt;</code> are evaluated sequentially in the dynamic
    128 environment.  If <code>&lt;body&gt;</code> is a non cyclic list, the last
    129 expression in <code>&lt;body&gt;</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>&lt;body&gt;</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