- Documentation
- 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(fastrw): Fast reading and writing of terms
- library(gensym): Generate unique symbols
- library(heaps): heaps/priority queues
- 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(macros): Macro expansion
- library(main): Provide entry point for scripts
- library(nb_set): Non-backtrackable set
- library(www_browser): Open a URL in the users 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_coverage): Coverage analysis tool
- library(prolog_debug): User level debugging tools
- library(prolog_jiti): Just In Time Indexing (JITI) utilities
- library(prolog_trace): Print access to predicates
- library(prolog_versions): Demand specific (Prolog) versions
- library(prolog_xref): Prolog cross-referencer data collection
- library(quasi_quotations): Define Quasi Quotation syntax
- library(random): Random numbers
- library(rbtrees): Red black trees
- library(readutil): Read utilities
- library(record): Access named fields in a term
- library(registry): Manipulating the Windows registry
- library(rwlocks): Read/write locks
- library(settings): Setting management
- library(statistics): Get information about resource usage
- 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
- Packages
- Reference manual
A.36 library(portray_text): Portray text
SWI-Prolog has the special string data type. However, in Prolog, text may be represented more traditionally as a list of character-codes, i.e. (small) integers (in SWI-Prolog specifically, those are Unicode code points). This results in output like the following (here using the backquote notation which maps text to a list of codes):
?- writeln(`hello`). [104, 101, 108, 108, 111] ?- atom_codes("hello",X). X = [104,101,108,108,111].
Unless you know the Unicode tables by heart, this is pretty
unpleasant for debugging. Loading library(portray_text)
makes the toplevel and debugger consider certain lists of integers as
text and print them as text. This is called "portraying". Of course,
interpretation is imperfect as there is no way to tell in general
whether [65,66]
should written as `AB`
or as [65,66]
.
Therefore it is important that the user be aware of the fact that this
conversion is enabled. This is why this library must be loaded
explicitly.
To be able to copy the printed representation and paste it back,
printed text is enclosed in back quotes if current_prolog_flag/2
for the flag
back_quotes
is codes
(the default), and
enclosed in double quotes otherwise. Certain control characters
are printed out in backslash-escaped form.
The default heuristic only considers list of codes as text if the codes are all from the set of 7-bit ASCII without most of the control characters. A code is classified as text by text_code/1, which in turn calls is_text_code/1. Define portray_text:is_text_code/1 to succeed on additional codes for more flexibility (by default, that predicate succeeds nowhere). For example:
?- maplist([C,R]>>(portray_text:text_code(C)->R=y;R=n), `G\u00e9n\u00e9rateur`,Results). Results = [y,n,y,n,y,y,y,y,y,y].
Now make is_text_code/1 accept anything:
?- [user]. |: portray_text:is_text_code(_). |: ^D % user://3 compiled 0.00 sec, 1 clauses true.
Then:
?- maplist([C,R]>>(portray_text:text_code(C)->R=y;R=n), `G\u00e9n\u00e9rateur`,Results). Results = [y,y,y,y,y,y,y,y,y,y].
- [det]portray_text(+OnOff:boolean)
- Switch portraying on or off. If
true
, consider lists of integers as list of Unicode code points and print them as corresponding text inside quotes:`text`
or"text"
. Quoting depends on the value of current_prolog_flag/2back_quotes
. Same as?- set_portray_text(enabled, true).
- [det]set_portray_text(+Key, +Value)
- [det]set_portray_text(+Key, ?Old, +New)
- Set options for portraying. Defined Keys are:
- enabled
- Enable/disable portray text
- min_length
- Only consider for conversion lists of integers that have a length of at least Value. Default is 3.
- ellipsis
- When converting a list that is longer than Value, display the
output as
start...end
.
- [semidet,multifile]is_text_code(+Code:nonneg)
- Multifile hook that can be used to extend the set of character codes
that is recognised as likely text. By default, is_text_code/1
fails everywhere and internally, only non-control ASCII characters
(32-126) and the the control codes (9,10,13) are accepted.
- To be done
- we might be able to use the current locale to include the appropriate code page. (Does that really make sense?)