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

peek-char


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

Syntax

(peek-char [skip-flag [source]])
skip-flag - an optional expression, default is NIL
source - an optional source, must be a file pointer or stream, default is *standard-input*
returns - the character

Description

The 'peek-char' function looks at a single character from the specified 'source'. The character looked-at is returned as an integer value for the result. If the 'skip-flag' expression is NIL , then the next character will be looked-at, without advancing the position within the file. If the 'skip-flag' expression is non-NIL , then the next non-white-space character will be looked-at. This skipping does advance the position within the file. White-space characters include 'blank', 'tab' and 'new-line' characters. If 'skip-flag' is not used, no skipping will occur. 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))  ; create file "f"
(print 12 fp)
(princ "  34" fp)
(terpri fp)
(close fp)

(setq fp (open "f" :direction :input))   ; open "f" for reading
(peek-char NIL fp)                       ; returns #\1
(peek-char NIL fp)                       ; returns #\1 - didn't advance
(read-char fp)                           ; returns #\1 - force advance
(peek-char NIL fp)                       ; returns #\2
(read-char fp)                           ; returns #\2 - force advance
(peek-char NIL fp)                       ; returns #\Newline
(peek-char T fp)                         ; returns #\3 - skipped blanks
(read-line fp)                           ; returns "34"
(close fp)

Common Lisp: The XLISP and Common Lisp 'peek-char' functions are compatible for simple cases. They both allow for the optional 'skip-flag' and 'source'. However, in Common Lisp, there are additional parameters which occur right after 'source' that support various end-of-file operations and recursive calls. So, when porting from Common Lisp to XLISP, remember there are additional arguments in Common Lisp's 'peek-char' that are not supported in XLISP.

See the peek-char function in the XLISP 2.0 manual.

  Back to Top


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