XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

read-byte


Type:   -   function (subr)
Source:   -   xlfio.c

Syntax

(read-byte [source])
source - an optional source, must be a file pointer or stream, default is *standard-input*
returns - the byte as an integer

Description

The 'read-byte' function reads a single character from the specified 'source'. The character read is returned as an integer value for the result. The 'source' may be a file pointer or a stream. If there is no 'source', *standard-input* is the default. If an end-of-file is encountered in the 'source', then NIL will be returned as the result.

Examples

(setq fp (open "f" :direction :output))  ; set up file
(print 12.34 fp)
(close fp)

(setq fp (open "f" :direction :input))   ; now read the file
(read-byte fp)                           ; returns 49  - equals "1"
(read-byte fp)                           ; returns 50  - equals "2"
(read-byte fp)                           ; returns 46  - equals "."
(read-byte fp)                           ; returns 51  - equals "3"
(read-byte fp)                           ; returns 52  - equals "4"
(read-byte fp)                           ; returns 10  - equals "\n"
(read-byte fp)                           ; returns NIL - empty
(close fp)

Common Lisp: The XLISP and Common Lisp 'read-byte' functions are compatible for simple cases. They both allow for the optional 'source'. However, in Common Lisp, there are additional parameters which occur right after 'source'. So, when porting from Common Lisp to XLISP, remember there are additional arguments in Common Lisp's 'read-byte' function.

Common Lisp: Common Lisp specifies that 'read' operations with a 'source' of NIL will come from *standard-input*. XLISP does not read the input from *standard-input* with a 'source' of NIL. Common Lisp also specifies that a 'source' of  T  will read from *terminal-io* which is not defined in XLISP by default. XLISP does not allow  T  as a valid argument for 'source'.

See the read-byte function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next