String, character and formatted I/O

String Input and Output

readstring(+NumChar, -String) readstring(+Handle, +NumChar, -String)

The readstring/2 and readstring/3 predicates are used for reading character strings from either the standard input device or from a file Handle, respectively. Each predicate takes an integer argument giving the number of 8-bit characters of the string to be read.

read_line(+Handle, -Line)

The readline/2 predicate is used to read lines of input. Unlike the readstring predicates, the read_line/2 predicate reads a full line of text, not a specified number of characters. The end of a line is indicated by crlf, cr, lf characters (cr and lf are ascii codes 13 and 10). You must specify an input handle (0 for standard input).

Character input and output

The get0 and put predicates, plus the other character input/output predicates, are described here. All characters are

get0(-Char) get0(+Handle, -Char)

The get0/1 and get0/2 predicates read a character from the standard input device or the specified file Handle, respectively.

get(-Char) get(+Handle, -Char)

Like the get0/1 and get0/2 predicates, get/1 and get/2 read a character from the standard input device or the specified file Handle. However, unlike the get0 predicates, get/1 and get/2 skip any non-printing characters. Non-printing characters have ASCII codes less than or equal to 32, such as the space, tab, cr and lf.

get0_noecho(-Char)

The get0_noecho predicate is only used to read a character from the standard input device. Unlike get0, when a character is input, it is not echoed on the standard output device.

keyb(-Ascii, -Scan) keyb(-Ascii, -Scan, -Flags)

Each key on the keyboard generates two codes and a set of flags. One code is the Ascii code, the other is the Scan code. The Flags provide information on the state keys, such as Shift or Alt, that were selected at the time of the key press. You can use the keyb/2 and keyb/3 predicates to read the codes and flags from the keyboard. You should experiment with various key presses and the keyb predicates to discover the ASCII and Scan codes that you want to capture for your application and hardware.

scan_code(+Ascii, -Scan)

The scan_code/2 predicate can be used to determine the Scan code corresponding to an ASCII code.

flush

Whenever you type a character at the keyboard, the operating system places the character in a type-ahead buffer. Whenever a character Input/Output predicate reads a character from the keyboard, it looks for the next character in the type-ahead buffer. If this buffer is empty, the predicate waits until a character is entered. The flush predicate removes all characters in the type-ahead buffer. The next Input/Output predicate to read from the keyboard will wait for a character to be entered.

skip(+Char) skip(+Handle, +Char)

The skip/1 and skip/2 predicates read and skip characters until a specific character is found. The characters can be read from the standard input device or from the specified file Handle.

put(+Char) put(+Handle, +Char)

Individual characters are written with the put/1 and put/2 predicates to either the standard output device or the specified file Handle.

nl nl(+Handle)

The nl and nl/1 predicates write a newline, consisting of a carriage return (cr, ascii 13) and line feed (lf, ascii 10) to the standard output device or the specified file Handle.

tab(+Num) tab(+Handle, +Num)

The tab/1 and tab/2 predicates write a given number of spaces to the standard output device or the specified file Handle.

Formatted data Input/Output

Arity/Prolog32 includes a number of for reading and writing fomatted integers, floating-point numbers, and strings from files.

writeint32(+Handle, +Integer) readint32(+Handle, -Integer)

The writeint32/2 predicate writes the Integer provided as a 32 bit integer to the file specified by Handle. The readint32/2 predicate reads the next 32 bit integer from the provided file Handle.

writeint16(+Handle, +Integer) readint16(+Handle, -Integer)

The writeint16/2 and readint16/2 predicates write and read a 16-bit integer specified by Integer to or from the file specified by Handle, the low order byte is written or read first.

writeint8(+Handle, +Integer) readint8(+Handle, -Integer)

The writeint8/2 and readint8/2 predicates write and read a 8-bit integer to or from the file specified by Handle. When read, the 8 bit integer is sign-extended to produce Integer.

writefloat(+Handle, +Float) readfloat(+Handle, -Float)

These writefloat/2 and readfloat/2 predicates write and read an 8 byte IEEE float value.

writeascib(+Handle, +Text) readascib(+Handle, -Text)

The writeascib/2 and readascib/2 predicates write or read 8-bit text characters preceded by an 8 bit unsigned integer length count. The maximum length is 255 bytes.

writeasciw(+Handle, +Text) readascicw(+Handle, -Text)

The writeasciw/2 and readasciw/2 predicates write or read 8-bit text characters preceded by an 16 bit unsigned integer length count. The maximum length is 65535 bytes.

writeasciz(+Handle, +Text) readasciz(+Handle, -Text)

The writeasciz/2 and readasciz/2 predicates write or read 8-bit text characters terminated by a 0 byte.

writeascizfield(+Handle, +Width, +Text) readascizfield(+Handle, +Width, -Text)

The writeascizfield/3 and readascizfield/3 predicates write or read 8-bit text characters, specified by Handle. The field contains at most Width characters that are followed by zeros if any room remains in the field. If the length of Text passed to writeascizfield/3 is less than the length of Width, then "zero" bytes are added to fill the field width. If the length of the string or atom specified by Text is greater than or equal to the field size specified by Width, then only the number of characters that can fit in the field length are written to the file specified by Handle.