11.3.152 peek_code/[1,2] [ISO]

Synopsis

peek_code(-Code)

peek_code(+Stream, -Code)

looks ahead for next input character on the input stream Stream.

Arguments

Stream
stream_object, must be ground

A valid input text stream, defaults to the current input stream.

Code
code or -1

The resulting next input character available on the stream.

Description

peek_code/[1,2] looks ahead of the next input character of the specified input stream and unifies the character with Code. The peeked character is still available for subsequent input on the stream.

Comments

Comments

It is safe to call peek_code/[1,2] several times without actually inputting any character. For example:

     | ?- peek_code(X), peek_code(X), get_code(X).
     |: a
     
     X = 97

Exceptions

Stream errors (see ref-iou-sfh-est), plus:

existence_error
Attempt to read past end of file, or some operating system dependent error occurred in reading.

See Also

ref-iou-cin.


Send feedback on this subject.