This library provides pure list-based I/O processing for Prolog, where the communication to the actual I/O device is performed transparently through coroutining. This module itself is just an interface to the actual implementation modules.
This module is part of
pio.pl, dealing with pure input:
processing input streams from the outside world using pure predicates,
notably grammar rules (DCG). Using pure predicates makes
non-deterministic processing of input much simpler.
Pure input uses coroutining (freeze/2) to read input from the external source into a list on demand. The overhead of lazy reading is more than compensated for by using block reads based on read_pending_input/3.
... --> |[_],... . file_contains(File, Pattern) :- phrase_from_file((..., Pattern, ...), File). match_count(File, Pattern, Count) :- findall(x, file_contains(File, Pattern), Xs), length(Xs, Count).
This can be called as (note that the pattern must be a string (code list)):
?- match_count('pure_input.pl', "file", Count).
buffer_size, which is passed to set_stream/2. If not specified, the default buffer size is 512 bytes. Of particular importance are the open/4 options
|Location||is a term |
Typically, this predicate is used as a building block for more high level safe predicates such as phrase_from_file/2.