type: function (subr) location: built-in source file: xlfio.c Common LISP compatible: similar supported on: all machines
(peek-char [ <skip-flag> [ <source> ] ] ) <skip-flag> - an optional expression - default is NIL <source> - an optional source - must be a file pointer or stream, the default is *standard-input*
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.
(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 COMPATIBILITY: 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 addition 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.