Interpreter.html (8502B)
1 <html lang="en"> 2 <head> 3 <title>Interpreter - 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="Introduction.html#Introduction" title="Introduction"> 9 <link rel="next" href="Booleans.html#Booleans" title="Booleans"> 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="Interpreter"></a> 28 <p> 29 Next: <a rel="next" accesskey="n" href="Booleans.html#Booleans">Booleans</a>, 30 Previous: <a rel="previous" accesskey="p" href="Introduction.html#Introduction">Introduction</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">2 Interpreter</h2> 37 38 <p><a name="index-interpreter-12"></a> 39 This section describes the <samp><span class="command">klisp</span></samp>, a Kernel Programming Language 40 stand-alone interpreter. 41 42 <h3 class="section">2.1 Invocation</h3> 43 44 <p><samp><span class="command">klisp</span></samp> is invoked like this: 45 <pre class="example"> klisp [options] [script] 46 </pre> 47 <h3 class="section">2.2 Description</h3> 48 49 <p><samp><span class="command">klisp</span></samp> is a stand-alone klisp interpreter for the Kernel 50 Programming Language. It loads and evaluates Kernel programs in 51 textual source form. <samp><span class="command">klisp</span></samp> can be used as a batch 52 interpreter and also interactively. The given <code>options</code> 53 (see <a href="Command-Line-Options.html#Command-Line-Options">Command Line Options</a>) are evaluated and then the klisp 54 program in file <code>script</code> is loaded and evaluated. All 55 evaluations mentioned, including the initialization that is described 56 below, take place in the same (initially) standard environment. All 57 values that result from these evaluation are discarded, but if the 58 <code>root-continuation</code> or <code>error-continuation</code> are passed a 59 value, the evaluation of <code>options</code> is interrupted and 60 <samp><span class="command">klisp</span></samp> terminates. 61 See <a href="Interpreter-Exit-Status.html#Interpreter-Exit-Status">Exit Status</a>, for a description of the 62 exit status in each case. 63 64 <p>The string <code>script</code> together with all arguments are available as 65 a list of strings via the applicative <code>get-script-arguments</code>. If 66 these arguments contain spaces or other characters special to the 67 shell, then they should be quoted (but note that the quotes will be 68 removed by the shell). The complete command line, including the name 69 of the interpreter, options, the script, and its arguments are 70 available as a list of strings via the applicative 71 <code>get-interpreter-arguments</code>. 72 73 <p>At the very beginning, before even handling the command line, 74 <samp><span class="command">klisp</span></samp> reads and evaluates the contents of the environment 75 variable <code>KLISP_INIT</code>, if it is defined. To use an init file, 76 just define <code>KLISP_INIT</code> to the following form: <code>(load 77 "/path/to/init-file")</code>. Notice that <samp><span class="command">klisp</span></samp> expects exactly one 78 expression in <code>KLISP_INIT</code>, if it is defined. So it is an error 79 to have no expressions or more than one in <code>KLISP_INIT</code>. The 80 same is true of the argument to the <code>-e</code> option, as both are 81 implemented in terms of <code>string-eval</code>. 82 <!-- TODO add xref to string-eval --> 83 84 <p>In interactive mode, <samp><span class="command">klisp</span></samp> prompts the user, reads 85 expressions from the standard input, and evaluates them as they are 86 read. The default prompt is "klisp> ". 87 88 <p><a name="Command-Line-Options"></a> 89 90 <h3 class="section">2.3 Options</h3> 91 92 <!-- @cindex Command Line Options --> 93 <!-- TODO move this to an appendix --> 94 <p>Options start with <samp><span class="option">-</span></samp> and are described below. You can use 95 <samp><span class="option">--</span></samp> to signal the end of options. If no arguments are given, 96 then <samp><span class="option">-v</span></samp> <samp><span class="option">-i</span></samp> is assumed when the standard input is a 97 terminal; otherwise, <samp><span class="option">-</span></samp> is assumed. If no <var>script</var>, or 98 option <samp><span class="option">-e</span></samp> or <code>-l</code> is given, <samp><span class="option">-i</span></samp> is assumed. 99 100 <dl> 101 <dt><samp><span class="option">-</span></samp><dd><!-- TODO implement option index @opindex - ... --> 102 <!-- cindex ... --> 103 load and execute the standard input as a file, 104 that is, 105 not interactively, 106 even when the standard input is a terminal. 107 .TP 108 109 <br><dt><samp><span class="option">-e </span><var>expr</var></samp><dd><!-- @opindex -e ... --> 110 <!-- @cindex -e ... --> 111 evaluate expression <var>expr</var>. You need to quote <var>expr</var> if it 112 contains spaces, quotes, or other characters special to the shell. 113 114 <br><dt><samp><span class="option">-i</span></samp><dd><!-- @opindex -i ... --> 115 <!-- @cindex -i ... --> 116 enter interactive mode after <var>script</var> is executed. 117 118 <br><dt><samp><span class="option">-l </span><var>name</var></samp><dd><!-- @opindex -l ... --> 119 <!-- @cindex -l ... --> 120 evaluate <code>(load "name")</code> before <var>script</var> is executed. 121 Typically used to do environment initialization. 122 123 <br><dt><samp><span class="option">-r </span><var>name</var></samp><dd><!-- @opindex -r ... --> 124 <!-- @cindex -r ... --> 125 evaluate <code>(require "name")</code> before <var>script</var> is 126 executed. Typically used to load libraries. 127 128 <br><dt><samp><span class="option">-v</span></samp><dd><!-- @opindex -v ... --> 129 <!-- @cindex -v ... --> 130 show version and copyright information. 131 132 </dl> 133 134 <!-- TODO move this to an appendix --> 135 <p><a name="Interpreter-Exit-Status"></a> 136 137 <h3 class="section">2.4 Exit Status</h3> 138 139 <!-- @cindex Exit Status --> 140 <p>If the <var>script</var> or <samp><span class="file">stdin</span></samp> reach <var>EOF</var> or if there is no 141 <var>script</var>, <code>EXIT_SUCCESS</code> is returned. If the 142 <var>error-continuation</var> is passed an object during init, arguments or script 143 evaluation <code>EXIT_FAILURE</code> is returned. If the 144 <var>root-continuation</var> is passed an object, <samp><span class="command">klisp</span></samp> tries to 145 convert the value passed to the <var>root-continuation</var> to an exit 146 status as follows: 147 148 <dl> 149 <dt><code>integer</code><dd>If the value is an integer it is used as exit status. 150 151 <br><dt><code>boolean</code><dd>If the value is a boolean then <code>EXIT_SUCCESS</code> is returned for 152 <code>#t</code> and <code>EXIT_FAILURE</code> for <code>#f</code>. 153 154 <br><dt><code>inert</code><dd>If the value is inert, then <code>EXIT_SUCCESS</code> is returned. 155 156 <br><dt><code>else</code><dd>In any other case <code>EXIT_FAILURE</code> is returned. 157 </dl> 158 159 <h3 class="section">2.5 Environment Variables</h3> 160 161 <!-- @cindex Interpreter Environment Variables --> 162 <p>The following environment variables affect the behaviour of <samp><span class="command">klisp</span></samp> 163 164 <dl> 165 <dt><samp><span class="env">KLISP_INIT</span></samp><dd><!-- TODO index for env variables --> 166 A Kernel expression to be evaluated before any arguments to the 167 interpreter. To use an init file, just define <var>KLISP_INIT</var> to the 168 following form <code>(load "/path/to/init-file")</code> 169 170 <br><dt><samp><span class="env">KLISP_PATH</span></samp><dd>A semicolon separated list of templates for controlling the search of 171 required files. Each template can use the char <code>?</code> to be 172 replaced by the required name at run-time. 173 174 </dl> 175 176 <!-- *-texinfo-*- --> 177 </body></html> 178