The dictionary implementation in Chapter 15 of The Art of Prolog efficiently implements a dictionary as an ordered, binary search tree using minimal code. Despite its apparent mutability, the dictionary is actually an incomplete data structure, making it partially-instantiated and theoretically immutable. The concept of incomplete data structures extends to difference lists as well, providing constant time list operations. By refactoring the dictionary implementation using newer techniques and predicates, the code becomes more efficient, flexible, and easier to understand. The authors also point out some limitations and suggest alternative approaches to improve the dictionary implementation.
https://blog.dnmfarrell.com/post/incomplete-data-structures/