National Institute of Advanced Industrial Science and Technology (AIST) This page is a page of the former research institute. We stopped updating on March 31.2001.
E-mail to webmaster (Japanese) E-mail to webmaster (English)
next up previous contents index
Next: Printer Up: Streams and Input/Output Previous: Streams

Reader

Reader's global variables:

*read-base*
number base to be read; default is decimal ten
*readtable*
current readtable which determines reader syntax

Reader's default macro characters:

 ( read list

" read string

' read quoted expression

# dispatch macro

; comment until end of line

` back-quote

, list-time eval

@ append

% read C-like mathematical forms

Escape characters:

  tex2html_wrap_inline28176  single character escape

|...| multiple character escape

When an unescaped symbol is read, all the constituent characters are converted to upcase by default, and upcase-character symbol is stored internally. For example, 'abc and 'ABC are regarded as the same symbol. Escape is necessary to distinguish between them. '|ABC|, 'ABC and 'abc are identical, while '|abc| and 'abc are different symbols. By default, even if you enter a symbol with upcase letters, When symbols are printed, EusLisp's printer converts them into lowercase from internal upcase representation. This conversion is suppressed by setting *print-case* to :UPCASE.

Note that 10. is read as integer 10, not floating 10.0. Since ':' is reserved for package marker, it must be escaped when used as a constituent of a symbol, like '|g:pcube|. This restriction is imposed not by the syntax of the character ':', but by the attribute which determines the alphabetical order and the meaning of the letter. The attributes of characters are hardwired in the reader. Thus, although you may change the syntax of a certain character by creating a new readtable by copy-readtable and resetting the syntactic meaning for the character by set-syntax-from-char, you cannot change its attribute anyway. In other words, digits are always digits, alphabets are alphabets, and we cannot use letters like '#$%@' to represent numbers.

% is an extended read-macro character specific to EusLisp. Preceding % to a mathematical formula written in infix notation, the formula is converted to lisp's prefix form. For an instance, %(1 + 2 * 3 / 4.0) is transformed to (+ 1 (/ (* 2 3) 4.0)) and 2.5 is resulted. C-like function calls and array references are converted to lisp forms, too, thus, %(sin(x) + a[1]) is evaluated to (+ (sin x) (aref a 1)). Functions having more than one arguments and arrays of more than two dimeisions are notated as func(a b c ...) and ary[1 2 3 ...], not func(a,b,c) nor ary[1][2][3]. Relative expressions and assignments are also properly handled, so, %(a < b) is converted to (< a b), and %(a[0] = b[0] * c[0]) is to (setf (aref b 0) (* (aref b 0) (aref c 0))). A simple optimization is performed to reduce duplicated function calls and array references. %(sin(x) + cos(x) / sin(x)) is converted into (let* ((temp (sin x))) (+ temp (/ (cos x) temp))).

Dispatch macros are preceeded by the # character. A number (integer) argument can be given between # and a dispatch macro character. This means that any digits (0 .. 9) cannot be defined as dispatch macro characters. Reader's standard dispatch macro characters follow:

#nA(..)
array
#B
binary number
#D
degree to radian conversion; #D180 = 3.14
#F(...)
floatvector
#nF((..))
float array; #2F((..) (..)) is matrix
#I(...)
integer-vector
#nI((...))
integer array
#J(...)
general object #J(myclass ....); obsolete
#O
octal number
#P
pathname
#R
radian to degree conversion; #R3.14 = 180.0
#S(classname slotname1 val1 slotname2 val2 ...)
structure (any object)
#V(...)
vector #V(vectorclass ...)
#X
hexadecimal number
#(...)
vector
#n#
label reference
#n=
label definition
#'
FUNCTION; compiled-code or lambda-closure
# tex2html_wrap_inline28176
character
#,
read-time evaluation
#+
conditional read (positive)
#-
conditional read (negative)
#*
bit vector
#:
uninterned symbol
#|...|#
comment; can be nested

Some reader functions have eof-error-p, eof-value and recursive-p parameters. The first two parameters control the behavior when the reader encounters with end-of-file. The default of eof-error-p is t, which causes an error at eof. If you want to know the occurrence of eof and don't want the system's error-handler to snatch control, specify nil to eof-error-p. Thus, when an eof appears during reading, the reader returns the eof-value instead of entering an error loop. Eof-value is defaulted to nil. So, you cannot know if nil is actually read, or eof appears. To distinguish them, give a value which can never appear in the stream. Use cons or gensym to make such unique data object.

Recursive-p is often used in read-macro functions, which call reader recursively. Non-nil value of recursive-p tells the reader that the read operation has been started somewhere else and it should not reset the internal table for reading forms labeled by #n= and #n#.

  read &optional stream (eof-error-p t) (eof-value nil) recursive-p [function]

  read-delimited-list delim-char &optional stream recursive-p [function]   read-line &optional stream (eof-error-p t) (eof-value nil) [function]   read-char &optional stream (eof-error-p t) (eof-value nil) [function]   read-from-string string &optional (eof-error-p t) (eof-value nil) [function]   unread-char char &optional stream [function]   peek-char &optional stream (eof-error-p t) (eof-value nil) [function]
  • reads a character from the stream without removing it from the buffer of the stream. This is equivalent to a read-char followed by a unread-char.
  y-or-n-p &optional format-string &rest args [function]
  • prints format-string and args on your terminal, and asks ``y-or-n''. Repeat query until your response begins with either of ``y'' or ``n'', and returns T or NIL. Case does not matter.
  yes-or-no-p &optional stream [function]
  • prints format-string and args on your terminal, and asks ``yes-or-no''. Repeat query until your response is either of ``yes'' or ``no'', and returns T or NIL. Case does not matter.
In the readtable manipulating functions, the default value of readtable is the value of the global variable *readtable*.

  readtable-p x [function]

  • T if x is an readtable.
  copy-readtable &optional from-readtable to-readtable [function]
  • If no to-readtable is specified, a new one is created. All the information in from-readtable is transferd to to-readtable. The information included is, syntax table, read-macro table and dispatch-macro table, each of which has 256 elements.
  set-syntax-from-char from-char to-char [from-readtable to-readtable] [function]
  • copies syntax and read-macro definition of from-char in from-readtable to that of to-char in to-readtable.
  set-macro-character char func [non-teminating-p readtable] [function]
  • defines func as the read-macro function for char.
  get-macro-character char [readtable] [function]
  • returns the read-macro function for char.
  set-dispatch-macro-character dispchar char func [readtable] [function]
  • defines func as the dispatch read-macro function for the combination of dispchar and char.
  get-dispatch-macro-character dispchar char [readtable] [function]
  • returns the dispatch read-macro function for the combination of dispchar and char.


next up previous contents index
Next: Printer Up: Streams and Input/Output Previous: Streams

Hirofumi Nakagaki
Fri Mar 22 12:46:38 JST 1996