- Reference manual
- The SWI-Prolog library
- library(aggregate): Aggregation operators on backtrackable predicates
- library(ansi_term): Print decorated text to ANSI consoles
- library(apply): Apply predicates on a list
- library(assoc): Association lists
- library(broadcast): Broadcast and receive event notifications
- library(charsio): I/O on Lists of Character Codes
- library(check): Consistency checking
- library(clpb): CLP(B): Constraint Logic Programming over Boolean Variables
- library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
- library(clpqr): Constraint Logic Programming over Rationals and Reals
- library(csv): Process CSV (Comma-Separated Values) data
- library(dcg/basics): Various general DCG utilities
- library(dcg/high_order): High order grammar operations
- library(debug): Print debug messages and test assertions
- library(dicts): Dict utilities
- library(error): Error generating support
- library(gensym): Generate unique identifiers
- library(increval): Incremental dynamic predicate modification
- library(intercept): Intercept and signal interface
- library(iostream): Utilities to deal with streams
- library(listing): List programs and pretty print clauses
- library(lists): List Manipulation
- library(main): Provide entry point for scripts
- library(nb_set): Non-backtrackable set
- library(www_browser): Activating your Web-browser
- library(occurs): Finding and counting sub-terms
- library(option): Option list processing
- library(optparse): command line parsing
- library(ordsets): Ordered set manipulation
- library(pairs): Operations on key-value lists
- library(persistency): Provide persistent dynamic predicates
- library(pio): Pure I/O
- library(portray_text): Portray text
- library(predicate_options): Declare option-processing of predicates
- library(prolog_debug): User level debugging tools
- library(prolog_jiti): Just In Time Indexing (JITI) utilities
- library(prolog_pack): A package manager for Prolog
- library(prolog_xref): Prolog cross-referencer data collection
- library(quasi_quotations): Define Quasi Quotation syntax
- library(random): Random numbers
- library(readutil): Read utilities
- library(record): Access named fields in a term
- library(registry): Manipulating the Windows registry
- library(settings): Setting management
- library(strings): String utilities
- library(simplex): Solve linear programming problems
- library(solution_sequences): Modify solution sequences
- library(tables): XSB interface to tables
- library(terms): Term manipulation
- library(thread): High level thread primitives
- library(thread_pool): Resource bounded thread management
- library(ugraphs): Graph manipulation library
- library(url): Analysing and constructing URL
- library(varnumbers): Utilities for numbered terms
- library(yall): Lambda expressions
- The SWI-Prolog library
- Reference manual
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.
- To be done
- Provide support for alternative input readers, e.g. reading terms, tokens, etc.
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 attributed variables 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_codes/3.
Ulrich Neumerkel came up with the idea to use coroutining for creating a lazy list. His implementation repositioned the file to deal with re-reading that can be necessary on backtracking. The current implementation uses destructive assignment together with more low-level attribute handling to realise pure input on any (buffered) stream.
- [nondet]phrase_from_file(:Grammar, +File)
- Process the content of File using the DCG rule Grammar.
The space usage of this mechanism depends on the length of the not
committed part of Grammar. Committed parts of the temporary
list are reclaimed by the garbage collector, while the list is extended
on demand due to unification of the attributed tail variable. Below is
an example that counts the number of times a string appears in a file.
The library dcg/basics provides
string//1 matching an
arbitrary string and remainder//1
which matches the remainder of the input without parsing.
:- use_module(library(dcg/basics)). file_contains(File, Pattern) :- phrase_from_file(match(Pattern), File). match(Pattern) --> string(_), string(Pattern), remainder(_). match_count(File, Pattern, Count) :- aggregate_all(count, file_contains(File, Pattern), Count).
This can be called as (note that the pattern must be a string (code list)):
?- match_count('pure_input.pl', `file`, Count).
- [nondet]phrase_from_file(:Grammar, +File, +Options)
- As phrase_from_file/2, providing additional Options. Options are passed to open/4.
- phrase_from_stream(:Grammar, +Stream)
- Run Grammer against the character codes on Stream. Stream must be buffered.
- Throw the syntax error Error at the current location of the
input. This predicate is designed to be called from the handler of phrase_from_file/3.
- Determine current (error) location in a lazy list. True when
Location is an (error) location term that represents the
current location in the DCG list.
Location is a term
file(Name, Line, LinePos, CharNo)or
stream(Stream, Line, LinePos, CharNo)if no file is associated to the stream RestLazyList. Finally, if the Lazy list is fully materialized (ends in
), Location is unified with
- See also
- lazy_list_character_count//1 only provides the character count.
- True when CharCount is the current character count in the
Lazy list. The character count is computed by finding the distance to
the next frozen tail of the lazy list. CharCount is one of:
- An integer
- A term end_of_file-Count
- See also
- lazy_list_location//1 provides full details of the location for error reporting.
- [det]stream_to_lazy_list(+Stream, -List)
- Create a lazy list representing the character codes in Stream.
List is a partial list ending in an attributed variable.
Unifying this variable reads the next block of data. The block is stored
with the attribute value such that there is no need to re-read it.
- Unlike the previous version of this predicate this version does not require a repositionable stream. It does require a buffer size of at least the maximum number of bytes of a multi-byte sequence (6).