This built-in clause reads a single character from the stream, the stream is altered. The ASCII value of the character is unified with the parameter 'in_integer', if the input stream is empty then the parameter 'in_integer' is unified with the atom 'end_of_file'.
The input stream must be a text stream that was opened for reading. If Char is a variable or an in_integer (an integer or the atom 'end_of_file') then:
This predicate is not part of the ISO Prolog standard, the built-in predicate char_code/2 can also be used to determine the integer ASCII value of a character. If the parameter @stream_or_alias is 'user' then input is read from the current input stream.
see also: get_char/1 get_code/1 get_code/2 peek_char/1 peek_char/2 peek_code/1 peek_code/2 prolog I/O put_char/1 put_char/2 put_code/1 put_code/2 nl/0 nl/1
| Example | |
| get0(user, A). | Assume the standard input stream has the contents: q, w, e,
... A is assigned the value 113 and the stream is left as: w, e, ... |
| get0(user, 117). | Assume the standard input stream has the contents: q, w, e,
... get0/2 fails, and a character was removed from the stream, the stream is left as: w, e, ... |
| Exceptions | |
| Char is neither a variable nor an in_integer | a type_error(in_integer, Char) is thrown |
| stream_or_alias is a variable | an instantiation_error exception is thrown |
| stream_or_alias is neither a variable nor a stream term nor an alias | a domain_error(stream_or_alias, Stream) exception is thrown, the variable Stream is assigned the incorrect stream_or_alias term |
| stream_or_alias is not associated with an open stream | an existence_error(stream, Stream) exception is thrown |
| stream_or_alias is an output stream | a permission_error(input, stream, Stream) exception is thrown |
| stream_or_alias is a binary stream | a permission_error(input, binary_stream, InputStream) is thrown, the variable InputStream is assigned the stream which was used as the input stream |
| current input stream has properties end_of_stream(past) and eof_action(error) | a permission_error(input, past_end_of_stream, InputStream) exception is thrown |