Did you know ... Search Documentation:
Pack nan_numerics_prime -- prolog/nan_numerics_prime_pio.pl
PublicShow source

Module prime_pio provides low-level predicates to read/write from/to a file or stream all consecutive prime numbers starting from 2 and up to a certain limit that is determined by the caller.

The accepted file format is a comma-separated list of the consecutive prime numbers starting from 2 and terminated by a period.

NOTE: Predicates in this module are not meant for public use.

author
- Julio P. Di Egidio
version
- 1.2.5-beta
license
- GNU GPLv3
 open_(+File:file, +Mode:oneof(read,write), :Goal:callable) is det
Opens File in Mode and calls back Goal(Stream) where Stream is the opened I/O stream. Mode can be one of read or write. File is automatically closed after Goal is finished.

Encoding of file is ascii, type is text, buffering is full.

Errors
- Errors from open/4.
 read_(+Stream:stream, :GAdd:callable) is det
Reads consecutive prime numbers from Stream. The file must not be empty and numbers must start at 2. For every read number greater than 2 calls GAdd(+P0:prime +P:prime), where P0 is the previously read number and P is the current number. Stops reading either at end-of-stream or when the call to GAdd fails.

Encoding of stream is ascii, type is text, buffer size is 1024.

NOTE: Does not check that the numbers read from the stream are consecutive prime numbers starting from 2.

Errors
- syntax_error(invalid_format) Input format is invalid.
- syntax_error(invalid_start) Input values must start at 2.
- syntax_error(invalid_value) Input values must be posint.
- Errors from read/2.
To be done
- Improve parse errors?
 write_(+Stream:stream, :GGen:callable) is det
Writes consecutive prime numbers to Stream. Always writes the number 2, then writes all numbers generated by calling GGen(-P:prime), where P shall be greater than 2. Stops writing when bactracking on GGen terminates.

Encoding of stream is ascii, type is text, buffering is full, buffer size is 1024.

NOTE: Does not check that the numbers generated by GGen are consecutive prime numbers starting from 3.

Errors
- Errors from write/2.