- 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(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_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(rbtrees): Red black trees
- library(readutil): Read utilities
- library(record): Access named fields in a term
- library(registry): Manipulating the Windows registry
- 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.15 library(dicts): Dict utilities
This library defines utilities that operate on lists of dicts, notably to make lists of dicts consistent by adding missing keys, converting between lists of compounds and lists of dicts, joining and slicing lists of dicts.
- [semidet]dicts_same_tag(+List, -Tag)
- True when List is a list of dicts that all have the tag Tag.
- [det]dict_size(+Dict, -KeyCount)
- True when KeyCount is the number of keys in Dict.
- [det]dict_keys(+Dict, -Keys)
- True when Keys is an ordered set of the keys appearing in Dict.
- [semidet]dicts_same_keys(+List, -Keys)
- True if List is a list of dicts that all have the same keys and Keys is an ordered set of these keys.
- dicts_to_same_keys(+DictsIn, :OnEmpty, -DictsOut)
- DictsOut is a copy of DictsIn, where each dict
contains all keys appearing in all dicts of DictsIn. Values
for keys that are added to a dict are produced by calling OnEmpty
as below. The predicate dict_fill/4
provides an implementation that fills all new cells with a predefined
value.
call(:OnEmpty, +Key, +Dict, -Value)
- [det]dict_fill(+ValueIn, +Key, +Dict, -Value)
- Implementation for the dicts_to_same_keys/3 OnEmpty
closure that fills new cells with a copy of ValueIn. Note
that
copy_term/2 does
not really copy ground terms. Below are two examples. Note that when
filling empty cells with a variable, each empty cell is bound to a new
variable.
?- dicts_to_same_keys([r{x:1}, r{y:2}], dict_fill(null), L). L = [r{x:1, y:null}, r{x:null, y:2}]. ?- dicts_to_same_keys([r{x:1}, r{y:2}], dict_fill(_), L). L = [r{x:1, y:_G2005}, r{x:_G2036, y:2}].
Use dict_no_fill/3 to raise an error if a dict is missing a key.
- [semidet]dicts_join(+Key, +DictsIn, -Dicts)
- Join dicts in Dicts that have the same value for Key,
provided they do not have conflicting values on other keys. For example:
?- dicts_join(x, [r{x:1, y:2}, r{x:1, z:3}, r{x:2,y:4}], L). L = [r{x:1, y:2, z:3}, r{x:2, y:4}].
- Errors
existence_error(key, Key, Dict)
if a dict in Dicts1 or Dicts2 does not contain Key.
- [semidet]dicts_join(+Key, +Dicts1, +Dicts2, -Dicts)
- Join two lists of dicts (Dicts1 and Dicts2) on Key.
Each pair D1-D2 from Dicts1 and Dicts2 that have
the same (
==
) value for Key creates a new dict D with the union of the keys from D1 and D2, provided D1 and D2 to not have conflicting values for some key. For example:?- DL1 = [r{x:1,y:1},r{x:2,y:4}], DL2 = [r{x:1,z:2},r{x:3,z:4}], dicts_join(x, DL1, DL2, DL). DL = [r{x:1, y:1, z:2}, r{x:2, y:4}, r{x:3, z:4}].
- Errors
existence_error(key, Key, Dict)
if a dict in Dicts1 or Dicts2 does not contain Key.
- [det]dicts_slice(+Keys, +DictsIn, -DictsOut)
- DictsOut is a list of Dicts only containing values for Keys.
- [semidet]dicts_to_compounds(?Dicts, +Keys, :OnEmpty, ?Compounds)
- True when Dicts and Compounds are lists of the
same length and each element of Compounds is a compound term
whose arguments represent the values associated with the corresponding
keys in
Keys. When converting from dict to row, OnEmpty is
used to compute missing values. The functor for the compound is the same
as the tag of the pair. When converting from dict to row and the dict
has no tag, the functor
row
is used. For example:?- Dicts = [_{x:1}, _{x:2, y:3}], dicts_to_compounds(Dicts, [x], dict_fill(null), Compounds). Compounds = [row(1), row(2)]. ?- Dicts = [_{x:1}, _{x:2, y:3}], dicts_to_compounds(Dicts, [x,y], dict_fill(null), Compounds). Compounds = [row(1, null), row(2, 3)]. ?- Compounds = [point(1,1), point(2,4)], dicts_to_compounds(Dicts, [x,y], dict_fill(null), Compounds). Dicts = [point{x:1, y:1}, point{x:2, y:4}].
When converting from Dicts to Compounds Keys may be computed by dicts_same_keys/2.