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
(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