1\chapter{Input and Output}
2
3\section{Introduction}
4
5One category of input and output in LISP is "symbolic" I/O.
6This allows a user to print or read possibly complex LISP
7objects with one or a few calls on standard functions. PSL also
8has powerful general-purpose I/O.
9
10Input from multiple sources and output to multiple destinations
11can be done in PSL all  at  the  same  time.  PSL
12provides  I/O  functions  with explicit specification of sources
13and destinations for I/O.  On the other hand for convenience  it
14is often desirable to let the source or destination be implicit.
15PSL  provides  the  full set of I/O operations through functions
16with an implicit source or destination.
17
18  The functions with and without an explicit channel  designator
19argument  are  described together in this chapter.  In each case
20calling the function with the implicit source or destination  is
21the  same  as calling the version with explicit channel argument
22and supplying the value of the  variable  in*  or  out*  as  the
23channel.
24
25  The  current input or output channel can be changed by setting
26or rebinding the variables {\bf in*}  or {\bf out*}.
27\index{*in}\index{*out}  Historically,  the
28functions  rds and wrs have been used for this and they are also
29available along with their special features.
30
31\subsection{Organization of this Chapter}
32
33  We first discuss  the  syntax  used  for  symbolic  input  and
34output.    The   syntax   described  applies  to  PSL  programs,
35interactive typein, format of data in data files, and to  output
36by PSL programs except when special formatting is used.
37
38  Functions  for  printing  and  reading  follow.  All (textual)
39input and output functions are discussed.   Next  is  open,  for
40setting  up input and output with files, plus related functions.
41A great deal of user input/output programming can be done  using
42just  a  subset  of  the  functions  described  in  these  first
43sections.
44
45  PSL includes functions that load program modules  and  execute
46command  files.    They  are  essential  to building of software
47systems even if the system itself does no  I/O.    Functions  of
48this type are described next.
49
50  The  section on I/O channels discusses some features available
51for switching the current output from channel  to  channel,  and
52documents  some  fluid  variables  used in directing some of the
53system's input and output.
54
55  Functions in the next section actually operate on objects such
56as lists and strings!  Since I/O functions scan input and format
57output, and since it is possible to read  from  or  print  to  a
58string, I/O functions can be useful for building strings and for
59scanning them.  Some built-in functions are described.
60
61  The  last  two sections describe mechanisms that make possible
62some sophisticated uses of the PSL I/O system.    One  describes
63the  mechanism in PSL that permits writing to a string or taking
64input from the  text  buffer  of  a  text  editor.    The  other
65discusses   the  tables  used  by  the  PSL  scanner,  which  is
66modifiable.
67
68\section{Printed Representation of LISP Objects}
69
70  Most of this section  is  devoted  to  the  representation  of
71tokens.   In addition to tokens there are composite objects with
72printed representations: lists and vectors.  We briefly  discuss
73their printed formats first.
74\begin{verbatim}
75"(" expression expression  . . . ")"
76"(" expression expression . . . "." expression)
77"[" expression expression . . . "]"
78\end{verbatim}
79
80  Of  these  the  first  two are for lists.  Where possible, the
81first notation is preferred and the  printing  routines  use  it
82except  when  the  second  form  is  needed.  The second form is
83required when the cdr of a pair is neither nil nor another pair.
84The third notation is for vectors.  For example:
85
86\begin{verbatim}
87(A . (B . C)) % An s-expression
88(A B . C)     % Same value, list notation
89(A B C)       % An ordinary list
90[A B C]       % A vector
91\end{verbatim}
92  The following standards for representing tokens are used:
93\begin{itemize}
94\item An id normally consists of uppercase  letters  and  digits.
95     The first character can be a digit when the first non-digit
96     character  is  a  plus  sign, minus sign, or a letter other
97     than "E" or "B".  We exclude lowercase letters because  the
98     PSL  reader  will  normally  convert  lowercase  letters to
99     uppercase.  Although the user may  use  lowercase  letters,
100     the  interpreter  only  sees uppercase.  This conversion is
101     controlled by the value of the switch *raise,  a  value  of
102     nil  will suppress this conversion.  In addition to letters
103     and  numbers,  the  following  characters  are   considered
104     alphabetic for the purpose of notating symbols.
105
106\begin{verbatim}
107     + - $ & * / : ; | < = > ? ^ _ ~ @
108\end{verbatim}
109     There is an escape convention for notating an id whose name
110     contains  special  characters.    In  addition to lowercase
111     letters the following characters are considered special.
112\begin{verbatim}
113     ! " % ' ( ) . [ ] ` , # |
114
115     JULIE     % three ways to notate the same symbol
116     julie
117     JuLie
118     +$
119     1+
120     +1        % this is a number, not an id
121     x^2+y^2   % a single symbol
122\end{verbatim}
123\item Strings begin with a  double  quote  (")  and  include  all
124     characters  up to a closing  double quote.  A  double quote
125     can  be included in  a string by  doubling it.    An  empty
126     string,  consisting    of only the  enclosing quote  marks,
127     is allowed.   The characters  of  a string are not affected
128     by the value of the *raise.  Examples:
129\begin{verbatim}
130     "This is a string"
131     "This is a ""string"""
132     ""
133\end{verbatim}
134\item Integers begin with a digit, optionally preceded by a +  or
135     - sign, and consist only of digits.  The global input radix
136     is 10; there is no way to change this.  However, numbers of
137     different  radices may be read by the following convention.
138     A decimal number from 2 to 36 followed by a sharp sign (\#),
139     causes the digits (and possibly letters) that follow to  be
140     read in the radix of the number preceding the \#. [Footnote:
141     Octal  numbers  can  also  be written as a string of digits
142     followed by the letter "B".] Thus  63  may  be  entered  as
143     8\#77,  or  255  as 16\#ff or 16\#FF.  The output radix can be
144     changed, by setting outputbase*.  If outputbase* is not 10,
145     the  printed  integer  appears  with   appropriate   radix.
146     Leading  zeros are suppressed and a minus sign precedes the
147     digits if the integer is negative.  Examples:
148\begin{verbatim}
149         100
150         +5234
151         -8#44 (equal to -36)
152\end{verbatim}
153
154\item Floats have a period and/or a letter "e" or  "E"  in  them.
155     Any of the following are read as floats.  The value appears
156     in  the format [-]n.nn...nnE[-]mm  if the magnitude  of the
157     number is    too    large  or    small  to    display    in
158     [-]nnnn.nnnn    format.      The    crossover    point   is
159     determined  by  the implementation.  In BNF,  floats    are
160     recognized by the grammar:
161\begin{verbatim}
162      <base>       ::= <unsigned-integer>.|
163                       .<unsigned-integer>|
164                       <unsigned-integer>.
165                      	<unsigned-integer>
166      <ebase>      ::= <base>|<unsigned-integer>
167      <unsigned-float> ::= <base>|
168                           <ebase>e<unsigned-integer>|
169                           <ebase>e-<unsigned-integer>|
170                           <ebase>e+<unsigned-integer>|
171                           <ebase>E<unsigned-integer>|
172                           <ebase>E-<unsigned-integer>|
173                           <ebase>E+<unsigned-integer>
174      <float>          ::= <unsigned-float>|
175                           +<unsigned-float>|
176                           -<unsigned-float>
177\end{verbatim}
178     That is:
179\begin{verbatim}
180         [+|-][nnn][.]nnn{e|E}[+|-]nnn
181
182         nnn.
183         .nnn
184         nnn.nnn
185\end{verbatim}
186     Examples:
187\begin{verbatim}
188         1e6
189         .2
190         2.
191         2.0
192         -1.25E-9
193\end{verbatim}
194
195\item Code-pointers  cannot  be read directly, but can be printed
196     and   constructed.      Currently   printed    as
197\begin{verbatim}
198    #<Code argument-count hexadecimal-address>.
199\end{verbatim}
200\item Anything  else is printed as \#$<$Unknown:nnnn$>$, where nnnn is
201     the hexadecimal value found in the argument register.  Such
202     items are not legal LISP entities  and  may  cause  garbage
203     collector  errors  if  they  are  found  in the heap.  They
204     cannot be read in.
205\end{itemize}
206
207\section{Functions for Printing}
208
209\subsection{Basic Printing}
210
211\de{prin1}{(prin1 ITM:any): ITM:any}{expr}
212{}
213
214\de{channelprin1}{(channelprin1 CHAN:io-channel ITM:any): ITM:any}{expr}
215{    Channelprin1  is  the  basic   printing   function.      For
216    well-formed,  non-circular  structures,  the  result  can be
217    parsed by the function read.
218}
219
220\de{prin2}{(prin2 ITM:any): ITM:any}{expr}
221{}
222
223\de{channelprin2}{(channelprin2 CHAN:io-channel ITM:any): ITM:any}{expr}
224{    Channelprin2 is similar to channelprin1, except that strings
225    are printed without the  surrounding  double  quotes,    and
226    delimiters  within  ids  are  not  preceded  by  the  escape
227    character.
228}
229
230		The following example illustrates the difference between prin1
231and prin2.
232
233\begin{verbatim}
234ARGUMENT     PRIN1        PRIN2
235
236A!%WORD      A!%WORD      A%WORD
237"STRING"     "STRING"     STRING
238\end{verbatim}
239
240\de{print}{(print U:any): U:any}{expr}
241{}
242
243\de{channelprint}{(channelprint CHAN:io-channel U:any): U:any}{expr}
244{    Display U using channelprin1 and  then  terminate  the  line
245    using channelterpri.
246}
247\subsection{Whitespace Printing Functions}
248
249\de{terpri}{(terpri): nil}{expr}
250{}
251
252\de{channelterpri}{(channelterpri CHAN:io-channel): nil}{expr}
253{    Write  an  end  of line character.  The number of characters
254    output on the current line  (that  which  is  referenced  by
255    channelposn),  is defined to be zero and the number of lines
256    output on the current page  (that  which  is  referenced  by
257    channelposn), is incremented.
258}
259
260\de{spaces}{(spaces N:integer): nil}{expr}
261{}
262
263\de{channelspaces}{(channelspaces CHAN:io-channel N:integer): nil}{expr}
264{    N spaces are written.
265}
266
267\de{tab}{(tab N:integer): nil}{expr}
268{}
269
270\de{channeltab}{(channeltab CHAN:io-channel N:integer): nil}{expr}
271{    Move to column N }
272
273{\tt(channelspaces ch (- N (channelposn ch)))}
274
275    If  the position on the current output line is past column N
276    then channelterpri is called before moving to column N.
277
278\subsection{Formatted Printing}
279
280\de{printf}{(printf FORMAT:string [ARGS:any]): nil}{expr}
281{}
282
283\de{channelprintf}{(channelprintf CHAN:io-channel FORMAT:string [ARGS:any]):nil}{expr}
284{   Channelprintf is a simple routine  for formatted  printing.
285    The  FORMAT  is a string.  The characters of this string are
286    printed unless a % is encountered.  The character  following
287    a  % is interpreted as a formatting directive and is used to
288    interpret and print the other  arguments  to  channelprintf.
289    The following format characters are currently supported.
290}
291
292\begin{tabular}{lp{11.0cm}}
293\%b & The next argument is assumed to be an integer, it is passed to spaces.\\
294\%c & The next argument should be a single character,
295   it is printed by	a call on writechar.\\
296\%d & Print the next argument as a decimal integer.\\
297\%e & The  next  argument  is evaluated by a call on eval.\\
298\%f & Print an end-of-line character if not
299 at  the  beginning  of  the output line
300  (does not use a matching argument).\\
301\%l & Print the next argument using print2l,
302this is the same as \%w except that lists
303 are  printed without  the  top  level
304  pair of parenthesis.
305		The empty list is printed as a blank.\\
306\%n & Print end-of-line character
307	(does  not  use  a matching argument).\\
308\%o & Print the next argument as an
309	octal integer.\\
310\%p & Print the next argument using prin1.\\
311\%p & Print the next argument using prin1.\\
312\%r & Print  the  next  argument  using errprin, the
313   result  is  the  same  as  \%p  except  that  a
314   surrounding pair of quotes are also printed.\\
315\%s & The  next  argument is assumed to be a string,
316   the surrounding double quotes are not printed.\\
317\%t & The next argument is assumed to be an integer,
318   it is passed to tab.\\
319\%w & Print the next argument using prin2.\\
320\%x & Print  the  next  argument  as  a  hexadecimal
321   integer.\\
322\end{tabular}
323
324    If  the character following \% is not either one of the above
325    or another \%, it  causes an error.  Thus, to include a \%  in
326    the format to be printed, use \%.
327
328    There  is  no checking for correspondence between the number
329    of arguments that FORMAT expects and the number given.    If
330    the  number  given  is  less  than  the number in the FORMAT
331    string, garbage will be inserted for the missing  arguments.
332    If the number given is greater than the number in the FORMAT
333    string, then the extra ones are ignored.
334
335
336\de{prettyprint}{(prettyprint U:form): U:form}{expr}
337{    Prettyprints U.
338}
339
340\subsection{The Fundamental Printing Function}
341
342\de{writechar}{(writechar CH:character): character}{expr}
343{}
344\de{channelwritechar}{(channelwritechar CHANNEL:io-channel\\
345CH:character): character}{expr}
346{
347    Write one character to the device specified by CHANNEL.  All
348    output  is defined in terms of this function.  The number of
349    characters  output  on  the  current  line  (that  which  is
350    referenced  by  channelposn), and the number of lines output
351    on  the  current  page  (that   which   is   referenced   by
352    channellposn),  are  updated.   Each  channel  specifies  an
353    output function,  it is this function  that  is  applied  to
354    CHANNEL and CH to actually write the character.
355}
356
357\subsection{Additional Printing Functions}
358
359\de{prin2l}{(prin2l L:any): {L:any, nil}}{expr}
360{    Prin2,  except  that a list is printed without the top level
361    parentheses.  If L is a pair then the return value  is  nil,
362    otherwise the return value will be L.  }
363
364\de{prin2t}{(prin2t X:any): any}{expr}
365{}
366\de{channelprin2t}{(channelprin2t CHAN:io-channel X:any): any}{expr}
367{    Output   X   using  channelprin2  and  terminate  line  with
368    channelterpri.
369}
370\de{princ}{(princ ITM:any): ITM:any}{expr}
371{}
372\de{channelprinc}{(channelprinc CHAN:io-channel ITM:any): ITM:any}{expr}
373{    Same function as channelprin2.
374}
375\de{errprin}{(errprin U:any): None Returned}{expr}
376{    Prin1 with special quotes to highlight U.
377}
378\de{errorprintf}{(errorprintf FORMAT:string [ARGS:any]): nil}{expr}
379{    Errorprintf is similar to  printf, except  that  errout*  is
380    used  in  place  of  the  currently selected output channel.
381    Channelterpri is called before and  after  printing  if  the
382    line position is greater than zero.  }
383
384\de{eject}{(eject): nil}{expr}
385{}
386\de{channeleject}{(channeleject CHAN:io-channel): nil}{expr}
387{    Skip to top of next output page.
388}
389
390\subsection{Printing Status and Mode}
391
392  For  information  on directing various kinds of output see the
393section on channels.
394
395\variable{outputbase*}{[Initially: 10]} {global}
396{    This fluid can be set to control the radix in which integers
397    are printed out.  If the radix is not 10, the radix is given
398    before a sharp sign.  }
399\begin{verbatim}
400    1 lisp> 16
401    16
402    2 lisp> (setq outputbase* 8)
403    8#10
404    3 lisp> 16
405    8#20
406\end{verbatim}
407\de{posn}{(posn): integer}{expr}
408{}
409
410\de{channelposn}{(channelposn CHAN:io-channel): integer}{expr}
411{    Returns number of characters output on the current  line  of
412    this channel.
413}
414
415\de{lposn}{(lposn): integer}{expr}
416{}
417
418\de{channellposn}{(channellposn CHAN:io-channel): integer}{expr}
419{    Returns number of lines output on this page of this channel.  }
420
421\de{linelength}{(linelength LEN:\{integer, nil\}): integer}{expr}
422{}
423
424\de{channellinelength}{(channellinelength CHAN:io-channel
425 LEN: \{integer, nil\}): integer}{expr}
426{   For  each  channel  there  is a restriction on the length of
427    output lines.  If LEN is nil then the value returned will be
428    the current maximum length.  If LEN is  an  integer  greater
429    than  zero then it will become the new maximum.  However, if
430    the argument is zero there will be no  restrictions  on  the
431    size of the output lines.  The following example illustrates
432    how  this  length  is  used.  PSL uses a similar function to
433    apply output functions like prin1.}
434\begin{verbatim}
435    (de check-line-length (length ch fn token)
436      (when (and (> (+ (channelposn ch) length)
437                    (channellinelength ch nil))
438                 (> (channellinelength ch nil) 0))
439        (channelwritechar ch (char eol)))
440      (idapply fn (list ch token)))
441\end{verbatim}
442The fluid variables PrinLevel and PrinLength allow the user to
443control how deep the printer will print and how many elements at
444a given level the printer  will  print.    This  is  useful  for
445objects  which  are  very large or deep.  These variables affect
446the functions prin1, prin2, princ, print, and  printf  (and  the
447corresponding Channel functions).
448
449\variable{prinlevel}{[Initially: nil]}{global}
450{   Controls how many levels deep a nested data object will print.
451  If PrinLevel is nil, then no control is exercised.  Otherwise the
452  value should be an integer. An object to be printed is at
453 level 0.
454}
455
456\variable{prinlength}{[Initially: nil]}{global}
457{
458  Controls how many elements at a given level are printed.   A
459  value  of nil indicates that there be no limit to the number
460  of components printed.  Otherwise the  value  of  PrinLength
461  should be an integer.
462}
463
464\section{Functions for Reading}
465
466\subsection{Reading S-Expressions}
467\de{read}{(read): any}{expr}
468
469\de{channelread}{(channelread CHAN:io-channel): any}{expr}
470{
471    Reads  and  returns the next S-expression from input channel
472    CHAN.  Valid input forms are: vector-notation, dot-notation,
473    list-notation,   numbers,    strings,    and    identifiers.
474    Identifiers are interned (see the intern function in Chapter
475    4),  unless  the  fluid  variable  *compressing  is non-nil.
476    Channelread returns the value of the global  variable \$eof\$
477    when  the  end  of  the  currently selected input channel is
478    reached.
479}
480\begin{verbatim}
481    (de channelread (ch)
482      (let ((currentscantable* lispscantable*)
483            (currentreadmacroindicator* 'lispreadmacro))
484        (channelreadtokenwithhooks ch)))
485\end{verbatim}
486    Channelread  uses  the  function  channelreadtokenwithhooks.
487    Tokens  are  scanned  within  the  context of the scan table
488    bound  to  lispscantable*.   The  scan  table  is  used   to
489    recognize  special  character types, for example, delimiters
490    like (, ), and space.  The read macro mechanism is  used  to
491    parse s-expressions (see section 12.4.5 for more information
492    on read macros).  PSL uses a number of read macros which are
493    described below.\\
494
495\begin{tabular}{lp{12.0cm}}
496    ( &             S-expressions  are  gathered into a list until
497                  the matching right parenthesis is read.   Both
498                  list  and dot notation are recognized.  A pair
499                  or list is returned.\\
500    ) &             If a right parenthesis is read and a  matching
501                  left  parenthesis had not been previously read
502                  then it will be ignored.\\
503    $[$ &       S-expressions are gathered into a vector until
504                  a matching right bracket is read.  A vector is
505                  returned.\\
506    '        &      The next  s-expression  read  is  quoted,  the
507                  result is of the form (QUOTE S-EXPRESSION).\\
508    (char eof) &    If  an  end  of file character is read while a
509                  list or vector is being constructed  then  the
510                  following error will occur.
511                  *****  Unexpected EOF while reading on channel.\\
512    `N' &	Otherwise the value of $eof$ is returned.\\
513\end{tabular}\\
514
515    The following read macros are defined in the {\tt useful} module.
516
517\begin{tabular}{lp{11.0cm}}
518    \#\' &            this is like the quote mark ' but it  is  used
519                  for  function  instead  of quote.  For example
520                  \#'name reads as (FUNCTION NAME).\\
521    \#/ &            this returns the numeric form of the following
522                  character  read  without  raising  it.     For
523                  example \#/a is 97 while \#/A is 65.\\
524    \#$\backslash$ & This  is  a read macro for char (see Chapter 6
525                  for more information).  Note that the argument
526                  will be raised  if  *raise  is  non-nil.   For
527                  example, \#$\backslash$a = \#$\backslash$A = 65.\\
528    \#. &            This  causes  the  following  expression to be
529                  evaluated at read time.  For  example,  `(1  2
530                  \#.(plus 1 2) 4) reads as (1 2 3 4).\\
531    \#+ &            The  next  two  expressions  are read.  If the
532                  first is a system name which  is  the  current
533                  system then the second expression is returned.
534                  Otherwise  another  expression  is read and it
535                  becomes the value returned.\\
536    \#- &            The next two expressions are  read.    If  the
537                  first  is  a  system  name  which  is  not the
538                  current system then the second  expression  is
539                  returned.    Otherwise  another  expression is
540                  read and it becomes the value returned.\\
541\end{tabular}
542
543\subsection{Reading Single Characters}
544
545\de{readchar}{(readchar): character}{expr}
546{}
547
548\de{channelreadchar}{(channelreadchar CHANNEL:io-channel):
549character}{expr} {
550Reads one character (an integer) from CHANNEL. All input is
551    defined in terms of this function.  If CHANNEL is  not  open
552    or  is  open  for  writing  only, an error is generated.  If
553    there is a non-zero value in the  backup  buffer  associated
554    with  CHANNEL,  the  buffer is emptied (set to zero) and the
555    value returned.  Otherwise, the reading function  associated
556    with  CHANNEL  is  called  with CHANNEL as argument, and the
557    value it returns is returned by channelreadchar.}
558\begin{verbatim}
559    ***** Channel not open
560\end{verbatim}
561\begin{verbatim}
562    ***** Channel open for write only
563\end{verbatim}
564\de{readch}{(readch): id}{expr}
565{}
566
567\de{channelreadch}{(channelreadch CHAN:io-channel): id}{expr}
568{    Like channelreadchar, but returns the id for  the  character
569    rather than its ASCII code.
570}
571
572\de{unreadchar}{(unreadchar CH:character): Undefined}{expr}
573{}
574
575\de{channelunreadchar}{(channelunreadchar CHAN:io-channel
576CH:character): Undefined}{expr}
577{
578    The  input  backup  function.  Ch is deposited in the backup
579    buffer associated with Chan.  This function should  be  only
580    called  after  channelreadchar  is  called,  and  before any
581    intervening input operations, since it is used by the  token
582    scanner.   The unread buffer only holds one character, so it
583    is generally useless to unread more than one character.
584}
585
586\subsection{Reading Tokens}
587
588  The functions described here pertain to the token scanner  and
589reader.   Globals  and  switches  used  by  these  functions are
590defined at the end of this section.
591
592\de{channelreadtoken}{(channelreadtoken CHANNEL:io-channel):
593\{id, number, string\}}{expr}
594{
595    This is the basic PSL token scanner.  The value returned  is
596    an  item  corresponding  to  the  next  token from the input
597    stream.    An  id  will  be  interned  unless   the   switch
598    {\bf *compressing}\index{*compressing} is  non-nil.
599    If *compressing is t then the
600    print name of the id is passed to  newid,  otherwise  it  is
601    passed  to  intern.
602}
603
604 	The global variable toktype* \index{toktype*} is set as
605    follows.
606
607\begin{tabular}{ll}
608    0 &             if the token is an ordinary id,\\
609
610    1 &            if the token is a string,\\
611
612    2 &             if the token is a number, or\\
613
614    3 &             if the token is an unescaped delimiter such as\\
615      &            "(", but not "!(" In this last case, the value\\
616      &            returned is the id whose  print  name  is  the\\
617      &            same as the delimiter.\\
618\end{tabular}
619
620The precise behavior of this function depends on two fluid
621variables:
622
623    Currentscantable* is bound to  a  vector  known  as  a  scan
624                  table.  Described below.
625
626    Currentreadmacroindicator* is bound to an id known as a read
627                  macro indicator.  Described below.
628
629\de{ratom}{(ratom): \{id, number, string\}}{expr}
630{    Reads a token from the current input channel.  }
631
632\de{channelreadtokenwithhooks}{(channelreadtokenwithhooks CHANNEL:io-channel):\\
633any}{expr}
634{    This   function  reads  a  token  and  performs  any  action
635    specified if the token is marked as a read macro  under  the
636    current  indicator.   Read  uses  this  function internally.
637    Uses the variable  currentreadmacroindicator*
638    {\index currentreadmacroindicator*} to  determine
639    the current indicator.
640}
641
642\subsection{Reading Entire Lines}
643
644\de{readline}{(readline): string}{expr}
645{ Same as (channelreadline in*)}
646\de{channelreadline}{(channelreadline CHANNEL:io-channel): string}{expr}
647{    A  string is returned which contains each character from the
648    current position of the scanner to the next  end-of-line  or
649    end-of-file character.
650}
651
652\subsection{Read Macros}
653
654  At  the  top  level  of  PSL,  an  expression  is  read, it is
655evaluated, and then the result is printed.  Normally a macro  is
656expanded  during evaluation.  The read macro is a different type
657of macro, it is expanded during the reading  phase.    When  the
658reader  encounters  a  read  macro  character,  the the macro is
659executed and the result is inserted in place of the  read  macro
660character.
661
662  A  read  macro  must be a function of two arguments, the first
663should represent a IO  channel,  the  second  a  character.    A
664character  which  represents  a read macro must be set to one of
665two types in the scan table.  It may be either a delimiter or  a
666diphthong.    Diphthong  corresponds  to  double  character read
667macros, delimiter to single character read macros.  In addition,
668the id which corresponds to the  character must have a reference
669to the name of the  function  on  its  property  list.    For  a
670diphthong  the  indicator must be lispdiphthong, for a delimiter
671it must be lispreadmacro.
672
673  The quote macro may be defined  as  follows.    Note  that  we
674cannot  use 'form in place of (quote form) until we have defined
675the read macro.
676
677\begin{verbatim}
678(de doquote (channel ch)
679  (list (quote quote) (channelread channel)))
680\end{verbatim}
681\begin{verbatim}
682(put (quote !') (quote lispreadmacro)(function doquote))
683\end{verbatim}
684\begin{verbatim}
685(putv lispscantable* (char !') delimiter)
686\end{verbatim}
687  This says that when a single quote is read, PSL should replace
688it with a list consisting of quote and the  next  expression  in
689the  input (obtained by an explicit call to channelread).  Since
690defining a character as a read macro makes it difficult  to  use
691the character in a normal way, read macros should not be letters
692or digits.
693
694\subsection{Terminal Interaction}
695
696\de{yesp}{(yesp MESSAGE:string): boolean}{expr}
697{    If the user responds y or yes, yesp returns a non-nil value.
698    A  response  of  n  or  no results in a value of nil.  It is
699    possible to enter a break loop by responding with b.   After
700    quitting  the  break loop, one must still respond y, yes, n,
701    or no.
702}
703
704\subsection{Input Status and Mode}
705
706\variable{promptstring*}{ [Initially: "x lisp$>$"]}{global}
707{
708    Displayed as a prompt when any  input  is  taken  from  TTY.
709    Prompts  should  therefore not be directly printed.  Instead
710    the value should be bound to promptstring*.
711}
712
713\variable{*eolinstringok}{[Initially: nil]}{switch}
714{
715    If *eolinstringok is non-nil, the warning message
716
717{\tt *** String continued over end-of-line }\\
718    is suppressed.
719}
720
721\variable{*raise}{ [Initially: t]}{switch}
722{
723    If *raise is  non-nil,  all  characters    input  for    ids
724    through  PSL input  functions are raised  to upper case.  If
725    *raise is nil, characters are input  as is.    A  string  is
726    unaffected by *raise.
727}
728
729\variable{*compressing}{[Initially: nil] }{switch}
730{
731    If  *compressing  is  non-nil,  channelreadtoken  and  other
732    functions that call it do not intern ids.
733}
734
735\variable{currentscantable*}{[Initially: NIL]}{global}
736{ This variable is set to lispscantable* by the function read }
737
738\variable{currentreadmacroindicator*}{ [Initially: NIL ]}{global}
739{
740    The  function  read  binds  this  variable  to   the   value
741    LISPREADMACRO.   Its  value  determines  the  property  list
742    indicator used in looking up read  macros.    The  user  may
743    define  a  set  of  read macros using some new indicator and
744    rebind this variable.  Ordinary read macros may be added  by
745    putting properties on ids under the LISPREADMACRO indicator.
746}
747
748\section{File System Interface: Open and Close}
749
750\de{open}{(open {\small FILENAME:string ACCESSTYPE:id):
751CHANNEL:io-channel}}{expr}
752{    If  AccessType  is eq to input or output, an attempt is made
753    to access  the  system-dependent  FILENAME  for  reading  or
754    writing.    If  the  attempt  is  unsuccessful,  an error is
755    generated;  otherwise  a  free  channel  is   returned   and
756    initialized  to  the  default  conditions  for ordinary file
757    input or output.
758}
759
760				If none of these conditions hold, a file is  not  available,
761    or there are no free channels, an error is generated.
762
763\begin{verbatim}
764    ***** Unknown access type
765    ***** Improperly set-up special IO open call
766    ***** File not found
767    ***** No free channels
768\end{verbatim}
769    If  AccessType is eq to SPECIAL, no file is opened.  Instead
770    the channel is initialized as  a  generalized  input  and/or
771    output stream.  See below.
772
773\de{filep}{(filep NAME:string): boolean}{expr}
774{    This  function will return t if file NAME can be opened, and
775    nil if not, e.g. if it does not exist.
776}
777
778\de{close}{(close CHANNEL:io-channel): io-channel}{expr}
779{    The closing function associated with CHANNEL is called, with
780    CHANNEL as its argument.  If it is illegal to close CHANNEL,
781    if CHANNEL is not open, or if CHANNEL is associated  with  a
782    file  and the file cannot be closed by the operating system,
783    this function  generates an error.   Otherwise,  CHANNEL  is
784    marked as free and is returned.
785}
786
787Here  is a simple example of input from a particular file with
788output sent to the current output channel.  This function  reads
789forms  from  the  file MYFILE.DAT and prints out all those whose
790				car is eq to  its  parameter.    Using  unwind-protect,  we  are
791				assured  that  the channel (and the file), will be closed in all
792				cases, including errors.
793
794\begin{verbatim}
795  (de filter-my-file (x)
796    (let ((chan (open "MYFILE.DAT" 'input))
797          form)
798      (unwind-protect
799        (while (neq (setq form (channelread chan))
800                    $eof$)
801               (if (and (pairp form) (eq (car form) x))
802                 (print form)))
803        (close chan))))
804\end{verbatim}
805
806\section{Loading Modules}
807
808Two convenient procedures are available for loading  modules.
809Various facilities described  in this manual are actually in
810loadable modules and their documentation notes that they must be
811loaded.  Loadable modules typically exist as FASL files .B
812files see the section on the compiler for information on
813producing FASL files.
814
815\de{load}{(load [FILE:\{string, id\}]): nil}{macro}
816{    For each argument FILE, an  attempt  is  made  to  locate  a
817    corresponding  file.   If  a  file  is found then it will be
818    loaded by a call on an appropriate function.   A  full  file
819    name is constructed by using the directory specifications in
820    loaddirectories* and the extensions in loadextensions*.  The
821    strings  from  each  list are used in a left to right order,
822    for a given string from loaddirectories* each extension from
823    loadextensions*   is   used.  More   information   about
824    loaddirectories* and loadextensions* can be found below.
825}
826
827While the file is being loaded *usermode will be set to nil.
828If a file cannot be found the call on load will be aborted.
829
830\begin{verbatim}
831    ***** `FILE' load module not found
832\end{verbatim}
833    If either *verboseload or *printloadnames is non-nil then
834    \index{*verboseload}\index{*printloadnames}
835
836\begin{verbatim}
837    *** loading FULL-NAME
838\end{verbatim}
839    is  printed just prior to loading the file.  Once a file has
840    been loaded the message
841
842\begin{verbatim}
843    *** FILE loaded
844\end{verbatim}
845    will  be  printed  if  the  *verboseload  is  non-nil.    In
846    addition,  the  name FILE is added to the list referenced by
847    options*.  If an attempt is made to load a  file  which  has
848    been partially loaded then
849
850\begin{verbatim}
851  *** Warning: Load of FILE previously requested, but incomplete.
852\end{verbatim}
853    will be printed.  If FILE is found to be  in  options*  then
854    the attempt to load FILE will be ignored.
855
856\begin{verbatim}
857    *** FILE already loaded
858\end{verbatim}
859    Note  that memq is used to determine if FILE is in options*.
860    Therefore when you use string arguments for  loading  files,
861    although  identical  names for ids refer to the same object,
862    identical names for strings refer to different objects.
863
864
865\de{reload}{(reload [FILE:\{string,id\}]): nil}{macro}
866{    Reload is very similar to load. The difference  between  the
867    two  is that for each name FILE, the first occurance of FILE
868    in options* will be removed before attempting  to  load  the
869    file.
870}
871
872\de{imports}{(imports FILES:list): nil}{expr}
873{    This  function  is also used to load modules.  If imports is
874    invoked as another module is being loaded, then the  modules
875    specified  by  FILES will not be loaded until the loading of
876    the current  module  is  complete.    Otherwise  imports  is
877    identical to load.
878}
879
880\variable{loaddirectories* }{[Initially: list]}{global}
881{ References  a list of strings to append to the front of
882file names passed as arguments to load, reload, and imports. }
883
884\variable{loadextensions*}{[Initially: association-list]}{global}
885{
886   References the a-list {\tt ((".b" . faslin) (".lap" . lapin)) }
887
888The car of  each  pair  is  a  string  which  represents  an
889extension  to  append to the end of the file names passed as
890arguments to load, reload,  and  imports.    The  cdr  is  a
891function  appropriate  for  loading  a  file of a particular
892extension.  For example, a file  whose  extension  is  B  is
893loaded with the function faslin.  }
894
895\variable{options*}{[Initially: nil]}{global}
896{
897    Once  a  file  corresponding  to  an argument FILE to either
898    load, reload, or imports has been loaded, FILE will be added
899    to the list referenced by options*.  An attempt  to  load  a
900    file  by applying load or imports will be aborted if FILE is
901    found in options*.  Reload removes the  first  occurance  of
902    FILE from options* before passing its argument to load.
903}
904
905\variable{*verboseload}{[Initially: nil]}{switch}
906{
907    If non-nil, a message is displayed when a request is made to
908    load  a  file  which has already been loaded, when a file is
909    about to be loaded, and  when  the  loading  of  a  file  is
910    complete.      Since  *redefmsg  is  set  to  the  value  of
911    *verboseload, a non-nil value  will also cause a message  to
912    be printed whenever a function is redefined during a load.
913}
914
915\variable{*printloadnames}{[Initially: nil]}{switch}
916{
917    If  non-nil, a message is printed when a file is about to be
918    loaded.
919}
920
921\section{Reading Files into PSL}
922
923The following procedures are used to read complete files  into
924PSL,  by  first calling open, and then processing each top level
925form in the file.  The effect is similar to what would happen if
926the file were typed into PSL.  File  names  are  represented  by
927strings.    File  names may be given using full system dependent
928file name conventions.
929
930\variable{*echo}{[Initially: nil]}{switch}
931{
932    The switch echo is used to control  the  echoing  of  input.
933    When  (on  echo) is placed in an input file, the contents of
934    the file are echoed on the standard output  device.    Dskin
935    does not change the value of *echo, so one may say (on echo)
936    before calling dskin, and the input will be echoed.
937}
938
939\de{dskin}{(dskin NAME:string): {nil, abort}}{expr}
940{    The contents of the file are processed as if they were typed
941    in.    If  the  processing of the file is aborted the return
942    value will be the identifier abort and the  following  error
943    message will be printed.
944}
945
946{\tt   ***** DSKIN of `NAME' aborted after N form(s) }\\
947
948A  count  of  each  top  level  form  is  kept  as  they are
949processed, which is the value N in the error message.   Once
950in*  has been bound to the channel which represents the open
951file, each form is processed by a function  similar  to  the
952one below.
953
954\begin{verbatim}
955  (de dskin-step ()
956    (let ((form (funcall toploopread*)))
957      (cond ((eq form $eof$) 'eof)
958            ((not *defn)
959             (funcall toploopprint* (funcall toploopeval* form))
960            (dfprint* (funcall dfprint* form))
961            (t (prettyprint form)))))
962\end{verbatim}
963
964Note  that  the  functions  used for reading, evaluating and
965    printing are the same as those used in toploop (see  Chapter
966    15  for more information).  If dfprint* has a value (and the
967    switch *defn is non-nil), then it will  be  applied  to  the
968    expression  instead  of  applying  the  functions  bound  to
969    toploopeval* and toploopprint*.  If dfprint* does not have a
970    value (and the switch *defn is  nil),  then  the  expression
971    will be simply be printed by a call on prettyprint.
972
973    Dskin  is  flagged  ignore.   This means that when a file is
974    compiled, a top level application of dskin will be evaluated
975    but not compiled.   For  more  information  about  the  flag
976    ignore see Chapter 19.
977
978\de{lapin}{(lapin NAME:string): \{nil, abort\}}{expr}
979{    Almost  identical  to  dskin. The  difference is that the
980    function bound to toploopprint* is not applied.  In general,
981    this means that the results of evaluation are not printed.
982}
983
984    Note that lapin is not flagged ignore as is dskin. This
985    means  that a top level application of lapin is compiled but
986    not evaluated.  For more information on how the flags ignore
987    and eval effect compilation see Chapter 19.
988
989\de{faslin}{(faslin FILENAME:string): nil}{expr}
990{    This is an efficient binary read loop, which fetches blocks
991    of  code,  constants  and  compactly  stored ids. It uses a
992    bit-table to relocate code and to identify special
993    LISP-oriented constructs.  FILENAME must be a complete file
994    name.
995}
996
997\section{About I/O Channels}
998
999\de{rds}{(rds {CHANNEL:io-channel, nil}): io-channel}{expr}
1000{    Rds sets in* to the value of its argument, and  returns  the
1001    previous value of in*.  In addition, if specialrdsaction* is
1002    non-nil,  it  should  be a function of 2 arguments, which is
1003    called with the old channel as its first  argument  and  the
1004    new channel as its second argument.  (rds nil) does the same
1005    as (rds stdin*).
1006}
1007
1008\de{wrs}{(wrs {CHANNEL:io-channel, nil}): io-channel}{expr}
1009{    Wrs  sets  out* to the value of its argument and returns the
1010    previous value of out*.  In addition,  if  specialwrsaction*
1011    is non-nil, it should be a function of 2 arguments, which is
1012    called  with  the  old channel as its first argument and the
1013    new channel as its second argument.  (wrs nil) does the same
1014    as (wrs stdout*).
1015}
1016  Global variables containing  information  about  channels  are
1017listed below.
1018
1019\variable{in*}{[Initially: 0]}{global}
1020{
1021    Contains  the  currently selected input channel.  May be set
1022    or rebound by the user.  This is  changed  by  the  function
1023    rds.
1024}
1025
1026\variable{out*}{[Initially: 1]}{global}
1027{
1028    Contains  the currently selected output channel.  May be set
1029    or rebound by the user.  This is  changed  by  the  function
1030    wrs.
1031}
1032
1033\variable{stdin*}{ [Initially: 0]}{global}
1034{
1035    The  standard  input  channel  (but not in the Unix sense of
1036    standard input).  Channel 0 is ordinarily the  terminal  and
1037    this variable is not intended to be set or rebound.
1038}
1039
1040\variable{stdout*}{[Initially: 1]}{global}
1041{
1042    The  standard  output channel.  Like channel 0, channel 1 is
1043    ordinarily always the terminal, and  this  variable  is  not
1044    intended to be set or rebound.
1045}
1046
1047\variable{breakin*}{[Initially: nil]}{global}
1048{
1049    The  channel  from  which the break loop gets its input.  It
1050    has been set to default  to  stdin*,  but  may  have  to  be
1051    changed on some systems with buffered-IO.
1052}
1053
1054\variable{breakout*}{[Initially: nil]}{global}
1055{
1056    The  channel  to  which the break loop sends its output.  It
1057    has been set to default to  stdout*,  but  may  have  to  be
1058    changed on some systems with buffered-IO.
1059}
1060
1061\variable{errout*}{[Initially: 1]}{global}
1062{
1063    The channel used by the errorprintf.
1064}
1065
1066\variable{specialrdsaction*}{[Initially: nil]}{global}{}
1067
1068\variable{specialwrsaction*}{[Initially: nil]}{global}{}
1069
1070\section{I/O to and from Lists and Strings}
1071
1072\de{bldmsg}{(bldmsg FORMAT:string, [ARGS:any]): string}{expr}
1073{    Printf to string.  This can be used as a very convenient way
1074    of  obtaining  the  printed  representation of an object for
1075    further  analysis.   In  many  cases  it  is  also  a   very
1076    convenient  way  of  constructing a needed string.  An error
1077    will occur on overflow.  Overflow occurs when the length  of
1078    the result exceeds the value of maxtokensize.
1079}
1080\begin{verbatim}
1081***** Buffer overflow while constructing error message: FORMAT
1082\end{verbatim}
1083\de{flatsize}{(flatsize U:any): integer}{expr}
1084{    Character length of prin1 S-expression.  }
1085
1086\de{flatsize2}{(flatsize2 U:any): integer}{expr}
1087{    Prin2 version of flatsize.  }
1088
1089\de{explode}{(explode U:any): id-list}{expr}
1090{    Explode takes the constituent characters of an  S-expression
1091    and forms a list of single character ids.  It is implemented
1092    via  the  function  channelprin1,  with a list rather than a
1093    file or terminal as destination.   Returned  is  a  list  of
1094    interned  characters representing the characters required to
1095    print the value of U.
1096}
1097\begin{verbatim}
1098    1 lisp> (explode 'foo)
1099    (f O O)
1100    2 lisp> (explode '(a . b))
1101    (!( a !  !. !  b !))
1102\end{verbatim}
1103
1104\de{explode2}{(explode2 U:{atom}-{vector}): id-list}{expr}
1105{    Prin2 version of explode.  }
1106
1107\de{compress}{(compress U:id-list): {atom}-{vector}}{expr}
1108{    U is a list of single character identifiers which  is  built
1109    into  a PSL  entity and returned.   Recognized are  numbers,
1110    strings,  and  identifiers  with    the   escape   character
1111    prefixing    special characters.  The formats of these items
1112    appear in the "Primitive Data Types" Section, Section 2.1.2.
1113    Identifiers are not interned on the id-hash-table.  Function
1114    pointers may not be compressed.   If  an  entity  cannot  be
1115    parsed out of U or characters are left over after parsing an
1116    error occurs: }
1117\begin{verbatim}
1118    ***** Poorly formed atom in COMPRESS
1119\end{verbatim}
1120\de{implode}{(implode U:id-list): atom}{expr}
1121{    Compress with ids interned.
1122}
1123
1124\section{Generalized Input/Output Streams}
1125
1126  All  input  and  output  functions are implemented in terms of
1127operations on "channels".  A channel is  just  a  small  integer
1128\footnote{ The   range   of  channel  numbers  is  from  0  to
1129MaxChannels, where MaxChannels is a  system-dependent  constant,
1130currently  31,  defined  in  the module {\bf io-decls}} which has 3
1131functions and some other information associated with  it.    The
1132three functions are:
1133
1134\begin{enumerate}
1135\item   A  reading  function,  which is called with the channel as
1136     its argument and returns the integer  ASCII  value  of  the
1137     next  character of the input stream.  If the channel is for
1138     writing only, this function is writeonlychannel.    If  the
1139     channel   has   not   been   opened,   this   function   is
1140     channelnotopen.  The reading function  is  responsible  for
1141     echoing characters if the flag *echo is non-nil.  It should
1142     use  the  function writechar to echo the character.  It may
1143     not be appropriate for a read function to echo  characters.
1144     For  example,  the  "disk"  reading  function does echoing,
1145     while the reader used to implement  the  compress  function
1146     does not.
1147
1148The  read function must also be concerned with the
1149handling of ends of "files" (actually, ends of
1150channels) and ends of lines.  It should return the
1151ASCII code for an end of  file character (system
1152dependent) when reaching the end of a channel. It
1153should return the ASCII code for a line  feed
1154character  to indicate an end of line (or "newline").
1155This may require that the ASCII code for carriage
1156return  be ignored when read, not returned.
1157
1158\item A writing function, which is called with the channel as its
1159first argument and the integer ASCII value of the
1160character to  write  as  its  second argument.  If
1161the channel is for reading only, this function is
1162readonlychannel. If the channel has not been
1163opened, this function is channelnotopen.
1164
1165
1166\item	A closing function, which is called with the channel as its
1167argument and performs any action necessary for the
1168graceful termination of input and/or output operations
1169to that channel. If the channel is not open, this
1170function is channelnotopen.
1171\end{enumerate}
1172
1173  The other information associated with a channel  includes  the
1174current  position in the output line (used by posn), the maximum
1175line  length  allowed  (used  by  linelength  and  the  printing
1176functions),  the  single  character input backup buffer (used by
1177the token scanner), and other system-dependent information.
1178
1179  Ordinarily, the user need not be aware  of  the  existence  of
1180this  mechanism. However,  because  of  its generality, it is
1181possible to implement operations other than  just  reading  from
1182and  writing  to  files  using  it. In  particular,  the LISP
1183functions explode and compress are performed  by  writing  to  a
1184list  and reading from a list, respectively (on channels 3 and 4
1185respectively).
1186
1187\subsection{Using the "Special" Form of Open}
1188
1189  If Open is called with AccessType eq to SPECIAL and the global
1190variables   specialreadfunction*,   specialwritefunction*,   and
1191specialclosefunction*  are  bound to ids, then a free channel is
1192returned and its associated functions are set to the  values  of
1193these  variables.    Other non system-dependent status is set to
1194default  conditions,  which  can  later  be  overridden.     The
1195functions  readonlychannel and writeonlychannel are available as
1196error handlers.  The parameter Filename is used only if an error
1197occurs.
1198
1199  The following globals  are  used  by  the  functions  in  this
1200section.
1201
1202\variable{specialclosefunction* }{[Initially: nil]}{global}{}
1203\variable{specialreadfunction*}{[Initially: nil]}{global}{}
1204\variable{specialwritefunction*}{[Initially: nil]}{global}{}
1205
1206\section{Scan Table Internals}
1207
1208The  scan  table controls the behaviour of the reader.  It can
1209be modified to extend the syntax of PSL or to aid the writing of
1210other parsers.  This table contains information about the syntax
1211of each character.   It  is  possible  to  have  several  tables
1212describing  different syntaxes and to switch from one to another
1213by binding the variable lispscantable*.
1214
1215	The table is a vector of 129 entries,  indexed  by  0  through
1216128.   The first 128 entries correspond to ASCII character code.
1217Each entry contains an integer between 0 and 21. The meaning  of
1218these numbers is given below.
1219
1220\begin{tabular}{lp{13.0cm}}
12210 \ldots 9 & DIGIT: indicates the character is a digit  and gives the
1222                   	corresponding numeric value.\\
122310 &       LETTER: indicates the character is alphabetic.\\
122411 &       DELIMITER: indicates the character is a delimiter, the first
1225                    character of a diphthong should not be classified as
1226                    a delimiter.\\
122712 &       COMMENT: indicates the character begins a comment, terminated
1228                  by an end of line.\\
122913 &       DIPHTHONG: indicates the character is a delimiter which may be
1230																						the
1231                    starting character of a diphthong.  A diphthong is a
1232                    two character sequence read as one token.\\
123314 &       IDESCAPE: indicates that the character is an escape character, this
1234                   character is used within id names to reference a character
1235                   which is not a digit or alphabetic.\\
123615 &       STRINGQUOTE: indicates that the character is used to delimit strings.\\
123716 &       PACKAGE: indicates that the character is used to introduce explicit
1238                  package names.\\
123917 &       IGNORE: indicates that the character is to be ignored.\\
124018 &       MINUS: indicates that the character represents a minus sign.\\
124119 &       PLUS: indicates that the character represents a plus sign.\\
124220 &       DECIMAL: indicates that the character represents a decimal point.\\
124321 &       IDSURROUND: indicates that the character is to act for identifiers
1244                     as a string quote for strings.\\
1245%\end{TABELLE***}
1246\end{tabular}
1247
1248\vspace{0.5cm}
1249It  may  be  tedious to insert an idescape character (!), before
1250every delimiter character in the name of an id.  By setting  the
1251type  of  a character (for example |), to idsurround this can be
1252avoided.  Every character between the vertical bars is taken  as
1253part  of  the  ids name, as if ! were written before each.  Note
1254that !! corresponds to ! and !| to |.
1255% establish | as the character to surround the name of ids
1256\begin{verbatim}
1257  (PUTV LISPSCANTABLE* (CHAR '|) IDSURROUND)
1258
1259|"|     % the same as !"
1260|dave|  % the name of the id is dave not DAVE
1261|!|!!|  % the name is |!, the same effect is gotten
1262        % by writing !|!!
1263\end{verbatim}
1264\variable{lispscantable*}{[Initially: as described below]}{global}
1265{
1266    Lispscantable* associates a type with each character.  It is
1267    a vector of 129 entries.  The type  for  a  character  C  is
1268    stored  at  index  (CHAR  C).    The  table below lists each
1269    character under its type.  The 128'th entry is the diphthong
1270    indicator, LISPDIPHTHONG.
1271}
1272
1273\begin{verbatim}
1274    DIGIT        0 through 9
1275    LETTER       a through z, A through Z, #, $, &, *, /,
1276                 @, ;, :, <, >, =, ^, _, {, }, |, ~, ?,
1277                 ^A through ^H, ^K, ^N through ^Y, ^\,^],
1278                 ^^, ^_, rubout
1279    DELIMITER    (, ), ', `, ^Z, [, ]
1280    COMMENT      %
1281    DIPHTHONG    ,
1282    IDESCAPE     !
1283    STRINGQUOTE  "
1284    PACKAGE      \
1285    IGNORE       null, tab, line-feed, ^L,
1286                 carriage-return	and space
1287    MINUS        -
1288    PLUS         +
1289    DECIMAL      .
1290\end{verbatim}
1291
1292\section{Scan Table Utility Functions}
1293
1294The following functions are provided to manage scan tables, in
1295the {\bf read-utils} module.
1296
1297\de{printscantable}{(printscantable TABLE:vector): nil}{expr}
1298{    Prints the entire scantable,  gives  the  0 ... 127  entries
1299    with  the  name  of  the  character  class.  Also prints the
1300    indicator used for diphthongs.
1301}
1302
1303\de{copyscantable}{(copyscantable OLDTABLE:\{vector, nil\}): vector}{expr}
1304{    Copies the existing scantable (or currentscantable* if given
1305    nil).  The 128'th entry (the diphthong  indicator),  of  the
1306    copy is set to the result of a call on gensym.
1307}
1308
1309\de{putdiphthong}{(putdiphthong TABLE:vector D1:id ID2:id DIP:id): nil}{expr}
1310{    Installs  DIP  as  the name of the diphthong Id1 followed by
1311    ID2 in the given scan table.
1312}
1313
1314\section{Binary I/O Functions}
1315
1316Binary input and output are necessary to provide an efficient access to
1317large files e.g. for loading or generating binary files (e.g. faslin
1318or faslout) or for
1319communication with other
1320processors e.g. graphics or database processors.
1321Another important application is the connection between two or more
1322PSL processors on incompatible platforms.
1323In the following descriptions HANDLE means something system specific
1324which in many cases should better not be interpreted by the LISP
1325evaluator. One can very well think of HANDLE as a FILE* object
1326belonging to the world of C's I/O library.
1327The results of a binary read function is usually not
1328meant for LISP evaluation, either.
1329
1330\de{binaryopenread}{(binaryopenread FILENAME:string): HANDLE}{expr}
1331{opens the file FILENAME for reading. If the file cannot be opened,
1332an error message {\tt Couldn't open binary file for input} will be shown,
1333an error condition is raised.}
1334
1335\de{binaryopenwrite}{(binaryopenwrite FILENAME:string): HANDLE}{expr}
1336{opens the file FILENAME for writing. If the file cannot be opened,
1337an error message {\tt Couldn't open binary file for output} will be shown,
1338an error condition is raised.}
1339
1340\de{binaryopenappend}{(binaryopenappend FILENAME:string): HANDLE}{expr}
1341{opens the file FILENAME in append mode. If the file cannot be opened,
1342an error message {\tt Couldn't open binary file for append} will be shown,
1343an error condition is raised.}
1344
1345\de{binaryopenupdate}{(binaryopenupdate FILENAME:string): HANDLE}{expr}
1346{opens the file FILENAME for update. If the file cannot be opened,
1347an error message {\tt Couldn't open binary file for update} will be shown,
1348an error condition is raised.}
1349
1350\de{binaryclose}{(binaryclose Filepointer:handle):NIL}{expr}
1351{Closes the file referenced by filepointer}
1352
1353\de{binaryread}{(binaryread CHANNEL:handle): any}{expr}
1354{reads one LISP item from file channel and returns it as value. There is
1355no way to distinguish error conditions from normal return values.}
1356
1357\de{binaryreadblock}{(binaryreadblock CHANNEL:handle ADDR:int SIZE:int): int}
1358{expr}
1359{reads SIZE LISP items from the file into an array pointed to by ADDR.
1360The number of actually read items is returned,
1361indicating error or end-of-file if the returned
1362value is less than the number of items requested.}
1363
1364\de{binarywrite}{(binarywrite CHANNEL:handle WORD:any): NIL}{expr}
1365{writes one LISP item in WORD to file channel.}
1366
1367\de{binarywriteblock}{(binarywriteblock Filepointer:handle ADDR:int SIZE:int):
1368NIL}
1369{expr}
1370{writes SIZE LISP items from the an array pointed to by ADDR to the file
1371referenced by Filepointer.
1372The number of actually written items is returned,
1373indicating error if the returned value is less than the number of
1374items requested.}
1375
1376\de{binarypositionfile}{(binarypositionfile CHANNEL:handle, SPECIAL:int): any}{expr}
1377{this corresponds to C's fseek operation. The special value (the address)
1378as well as the
1379return value is system dependent, please investigate.}
1380