Scryer Prolog documentation

Module pio

:- use_module(library(pio)).

Pure I/O.

Our goal is to encourage the use of definite clause grammars (DCGs) for describing strings. The predicates phrase_from_file/[2,3], phrase_to_file/[2,3] and phrase_to_stream/2 let us apply DCGs transparently to files and streams, and therefore decouple side-effects from declarative descriptions.

phrase_from_file(+GRBody, +File)

True if grammar rule body GRBody covers the contents of File, represented as a list of characters.

phrase_from_file(+GRBody, +File, +Options)

Like phrase_from_file/2, using Options to open the file.

phrase_to_file(+GRBody, +File)

Write the string described by GRBody to File.

phrase_to_file(+GRBody, +File, +Options)

Like phrase_to_file/2, using Options to open the file.

phrase_to_stream(+GRBody, +Stream)

Emit the list of characters described by the grammar rule body GRBody to Stream.

An ideal implementation of phrase_to_stream/2 writes each character as soon as it becomes known and no choice-points remain, and thus avoids the manifestation of the entire string in memory. See #691 for more information.

The current preliminary implementation is provided so that Prolog programmers can already get used to describing output with DCGs, and then writing it to a file when necessary. This simple implementation suffices as long as the entire contents can be represented in memory, and thus covers a large number of use cases.