5 SWI-Prolog extensions

This chapter describes extensions to the Prolog language introduced with SWI-Prolog version 7 in 2014. The changes bring more modern syntactical conventions to Prolog such as key-value maps, called dicts, as primary citizens and a restricted form of functional notation. They also extend Prolog basic types with strings, providing a natural notation to textual material as opposed to identifiers (atoms) and lists.

These extensions make the syntax more intuitive to new users, simplify the integration of domain specific languages (DSLs) and facilitate a more natural Prolog representation for popular exchange languages such as XML and JSON.

While many programs run unmodified in SWI-Prolog version 7, some require modifications, especially those that pass double quoted strings to general purpose list processing predicates. See section 5.2.4 and section 5.2.5 for information and tools on porting. We provide a tool (list_strings/0) that we used to port a huge code base in half a day.


Section Index


5.1 Lists are special
5.1.1 Motivating‘[|]’and [] for lists
5.2 The string type and its double quoted syntax
5.2.1 Representing text: strings, atoms and code lists
5.2.2 Predicates that operate on strings
5.2.3 Why has the representation of double quoted text changed?
5.2.4 Adapting code for double quoted strings
5.2.5 Predicates to support adapting code for double quoted strings
5.3 Syntax changes since SWI-Prolog 7
5.3.1 Operators and quoted atoms
5.3.2 Compound terms with zero arguments
5.3.3 Block operators
5.4 Dicts: structures with named arguments
5.4.1 Functions on dicts
5.4.1.1 User defined functions on dicts
5.4.1.2 Predefined functions on dicts
5.4.2 Predicates for managing dicts
5.4.2.1 Destructive assignment in dicts
5.4.3 When to use dicts?
5.4.4 A motivation for dicts as primary citizens
5.4.5 Implementation notes about dicts
5.5 Integration of strings and dicts in the libraries
5.5.1 Dicts and option processing
5.5.2 Dicts in core data structures
5.5.3 Dicts, strings and XML
5.5.4 Dicts, strings and JSON
5.5.5 Dicts, strings and HTTP
5.6 Single Sided Unification rules
5.6.1 Single Sided Unification Guards
5.6.2 Consequenses of => single sided unification rules
5.6.3 SSU: Future considerations
5.7 Remaining issues