get_code(@stream_or_alias, ?in_character_code) [ISO]

This built-in clause reads a single character code from the stream, the stream is altered. The input stream must be a text stream that was opened for reading. If Code is a variable or an in_character_code (a character code or the integer -1) then:

see also: get_byte/1 get_byte/2 get_char/1 get_char/2 get_code/1 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
get_code(user_in, A). Assume there is an input stream called user_in and it has contents: q, w, e, ...
A is assigned the value 113 and the stream is left as: w, e, ...
get_code(user_in, 117). Assume there is an input stream called user_in and it has contents: q, w, e, ...
get_code/2 fails, and a character was removed from the stream, the stream is left as: w, e, ...

 

Exceptions  
Code is neither a variable nor an integer a type_error(integer, Code) exception is thrown
Code is an integer but not an in_character_code a representation_error(in_character_code) exception 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

 

 

info@trinc-prolog.com