| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 
 | <html><head>
<title>XLISP reader</title>
<style type="text/css">
.example {
  color: #000000;
  background-color: #F5F5F5;
  padding: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  width:auto;
}
.button {
  color: #000000;
  background-color: #F5F5F5;
  padding-top: 1px;
  padding-bottom: 1px;
  padding-left: 4px;
  padding-right: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  white-space: pre;
}
.box {
  color: #000000;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 16px;
  padding-right: 16px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
}
</style>
</head>
<body>
<a href="../start.htm">Nyquist / XLISP 2.0</a>  - 
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="examples.htm">Examples</a> |
<a href="../reference/reference-index.htm">Reference</a>
<hr>
<h1>Reader</h1>
<hr>
<hr>
<h2>read-from-string</h2>
<hr>
<pre class="example">
(defun <font color="#0000CC">read-from-string</font> (string)
  (read (make-string-input-stream string)))
</pre>
<p><nobr>  <a href="#top">Back to top</a></nobr></p>
<a name="global-readtable"></a>
<hr>
<h2>*readtable*</h2>
<hr>
<p>The <a href="../reference/global-readtable.htm">*readtable*</a> system
variable contains the reader table array. <nobr>The table</nobr> is
<nobr>128 entries</nobr> <nobr>[0..127]</nobr> for each of the
<nobr>7-bit</nobr> ASCII characters that XLISP
<nobr>can <a href="../reference/read.htm">read</a></nobr>.</p>
<ul>
<li><nobr><a href="../reference/read.htm">read</a> - function to read a lisp expression</nobr></li>
<li><nobr><a href="../reference/global-readtable.htm">*readtable*</a> - system variable, holding the readtable</nobr></li>
<ul>
<li><nobr><a href="../reference/nil.htm">NIL</a> - invalid character</nobr></li>
<li><nobr><a href="../reference/keyword-constituent.htm">:constituent</a> - symbol constituent</nobr></li>
<li><nobr><a href="../reference/keyword-sescape.htm">:sescape</a> - whitespace character</nobr></li>
<li><nobr><a href="../reference/keyword-mescape.htm">:mescape</a> - multiple escape character</nobr></li>
<li><nobr><a href="../reference/keyword-white-space.htm">:white-space</a> - single escape character</nobr></li>
<li><nobr><a href="../reference/keyword-tmacro.htm">:tmacro</a> - terminating readmacro</nobr></li>
<li><nobr><a href="../reference/keyword-nmacro.htm">:nmacro</a> - non-terminating readmacro</nobr></li>
</ul>
</ul>
<p>See also the
<nobr><a href="../manual/xlisp.htm#lexical-conventions">Lexical Conventions</a></nobr>
and  <a href="../manual/xlisp.htm#the-readtable">Readtable</a> sections in the
<nobr>XLISP 2.0</nobr> manual.</p>
<a name="print-readtable"></a>
<hr>
<h2>print-readtable</h2>
<hr>
<pre class="example">
(defun <font color="#0000CC">print-readtable</font> ()
  (dotimes (index 128)
    (format t <font color="#880000">"ASCII-~a ~a = ~a~%"</font>
              (cond ((<=  0 index  9) (format nil "00~a" index))
                    ((<= 10 index 99) (format nil "0~a"  index))
                    (t index))
              (if (< 31 index 127)
                  (code-char index)
                  (case index
                    (0   "[null]                  ")
                    (1   "[start of heading]      ")
                    (2   "[start of text]         ")
                    (3   "[end of text]           ")
                    (4   "[end of transmission]   ")
                    (5   "[enquiry]               ")
                    (6   "[acknowledge]           ")
                    (7   "[terminal bell]         ")
                    (8   "[backspace]             ")
                    (9   "[horizontal tab]        ")
                    (10  "[line feed]             ")
                    (11  "[vertical tab]          ")
                    (12  "[form feed]             ")
                    (13  "[carriage return]       ")
                    (14  "[shift out]             ")
                    (15  "[shift in]              ")
                    (16  "[data link escape]      ")
                    (17  "[device control 1, xon] ")
                    (18  "[device control 2]      ")
                    (19  "[device control 3, xoff]")
                    (20  "[device control 4]      ")
                    (21  "[negative acknowledge]  ")
                    (22  "[synchronous idle]      ")
                    (23  "[end transmission block]")
                    (24  "[cancel line]           ")
                    (25  "[end of medium]         ")
                    (26  "[substitute]            ")
                    (27  "[escape]                ")
                    (28  "[file separator]        ")
                    (29  "[group separator]       ")
                    (30  "[record separator]      ")
                    (31  "[unit separator]        ")
                    (127 "[delete]")))
              (aref <font color="#AA5500">*readtable*</font> index))))
</pre>
<hr>
<h2>get-macro-character</h2>
<hr>
<p><div class="box">
<dl>
<dt>(<b>get-macro-character</b> <i>char</i>)</dt>
<dd><i>char</i> - a character<br>
returns - the code associated with the
<a href="../reference/global-readtable.htm">*readtable*</a> entry or
<a href="../reference/nil.htm">NIL</a></dd>
</dl>
</div></p>
<pre class="example">
(defun <font color="#0000CC">get-macro-character</font> (char)
  (if (consp (aref <font color="#AA5500">*readtable*</font> (char-code char)))
      (cdr (aref <font color="#AA5500">*readtable*</font> (char-int char)))
      nil))
</pre>
<p> The '<nobr>get-macro-character</nobr>' function returns the code that
will be executed when the specified character 'char' is encountered by the
XLISP reader.</p>
<p>The 'get-macro-character' function will return a
<a href="../reference/nil.htm">NIL</a> value if the table entry is
<nobr><a href="../reference/nil.htm">NIL</a> ,</nobr>
<nobr><a href="../reference/keyword-constituent.htm">:constituent</a> ,</nobr>
<nobr><a href="../reference/keyword-sescape.htm">:sescape</a> ,</nobr>
<a href="../reference/keyword-mescape.htm">:mescape</a> or
<a href="../reference/keyword-white-space.htm">:white-space</a>. If the table entry is
<a href="../reference/keyword-tmacro.htm">:tmacro</a> or
<nobr><a href="../reference/keyword-nmacro.htm">:nmacro</a> ,</nobr> then the code
associated with the entry is returned.
<a href="../reference/keyword-tmacro.htm">:tmacro</a> is used for a terminating
read-macro. <a href="../reference/keyword-nmacro.htm">:nmacro</a> is used for a
non-terminating read-macro. 'get-macro-character' does not differentiate
whether the code returned is a
<a href="../reference/keyword-tmacro.htm">:tmacro</a> or an
<a href="../reference/keyword-nmacro.htm">:nmacro</a>.</p>
<p>The function returned may be a built-in read-macro function or a user
defined <a href="../reference/lambda.htm">lambda</a> expression. The function
takes two parameters, an input stream specification, and an integer that is
the character value. The function should return
<a href="../reference/nil.htm">NIL</a> if the character is 'white-space' or a
value <a href="../reference/cons.htm">cons</a>ed with
<a href="../reference/nil.htm">NIL</a> to return the value.</p>
<p>Examples:</p>
<pre class="example">
(get-macro-character #\()      => #<Subr-(null): #...></font>
(get-macro-character #\#)      => #<Subr-(null): #...></font>
(get-macro-character #\Space)  => NIL</font>
</pre>
<p><nobr>  <a href="#top">Back to Top</nobr></a></p>
<a name="set-macro-character"></a>
<hr>
<h2>set-macro-character</h2>
<hr>
<p><div class="box">
<dl>
<dt>(<b>set-macro-character</b> <i>char function</i> [<i>termination-flag</i>])</dt>
<dd><i>char</i> - a character expression<br>
<i>function</i> - a function definition<br>
<i>termination-flag</i> - an expression, <a href="../reference/nil.htm">NIL</a> or
non-<a href="../reference/nil.htm">NIL</a><br>
returns - always returns <a href="../reference/t.htm"> T </a></dd>
</dl>
</div></p>
<pre class="example">
(defun <font color="#0000CC">set-macro-character</font> (char function &optional terminate-p)
  (setf (aref <font color="#AA5500">*readtable*</font> (char-code char))
        (cons (if terminate-p :tmacro :nmacro) function))
  t)
</pre>
<p>The '<nobr>set-macro-character</nobr>' function installs the code that
will be executed when the specified character 'char' is encountered by the
XLISP reader.</p>
<p>The 'set-macro-character' function only allows you to put in a
terminating read-macro function <a href="../reference/keyword-tmacro.htm">:tmacro</a> or
a non-terminating read-macro-function
<a href="../reference/keyword-nmacro.htm">:nmacro</a>. If the 'termflag' is present and
non-<nobr><a href="../reference/nil.htm">NIL</a> ,</nobr> then the 'function'
will be put in <a href="../reference/global-readtable.htm">*readtable*</a> as a
<a href="../reference/keyword-tmacro.htm">:tmacro</a> entry. If 'termflag' is not present
or <nobr><a href="../reference/nil.htm">NIL</a> ,</nobr> then 'function' will
be put in <a href="../reference/global-readtable.htm">*readtable*</a> as a
<a href="../reference/keyword-nmacro.htm">:nmacro</a> entry. The 'function' can be a
built-in read-macro function or a user defined
<a href="../reference/defun.htm">defun</a> symbol or a
<a href="../reference/lambda.htm">lambda</a> expression.</p>
<p>The 'function' takes two parameters, an input stream specification, and
an integer that is the character value. The 'function' should return
<a href="../reference/nil.htm">NIL</a> if the character is 'white-space' or a
value <a href="../reference/cons.htm">cons</a>ed with
<a href="../reference/nil.htm">NIL</a> to return the value. The function
'set-macro-character' always returns
<a href="../reference/t.htm"> T </a>.</p>
<p>Examples:</p>
<pre class="example">
> (print "hi") % comment
"hi"
"hi"
<font color="#AA0000">error: unbound variable - %</font>       <font color="#008844">; % is interpreted as a variable</font>
> (setq readtable-backup *readtable*)
#( ... very-long-value ... )
> (set-macro-character #\% (get-macro-character #\;) t)
T
> (print "hi") % comment
"hi"                              <font color="#008844">; no error because</font>
"hi"                              <font color="#008844">; % is now a comment character</font>
> (setq *readtable* readtable-backup)
#( ... very-long-value ... )
</pre>
<p><b>Important:</b> before manipulating the XLISP
<a href="../reference/global-readtable.htm">*readtable*</a> it's always a
good idea to store the original contents in some other variable.</p>
<p><nobr>  <a href="#top">Back to Top</nobr></a></p>
<hr>
<a href="../start.htm">Nyquist / XLISP 2.0</a>  - 
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="examples.htm">Examples</a> |
<a href="../reference/reference-index.htm">Reference</a>
</body></html>
 |