TL;DR
An author preparing a new edition of Logic for Programmers revisits long-standing frustrations with Prolog’s design and ecosystem. Key complaints include inconsistent string support, the absence of functions and native booleans, limited collection types, and confusing control constructs like cuts and negation.
What happened
While preparing the next edition of his book Logic for Programmers, the author revisited parts of Prolog that have long irritated him. He lists several pragmatic and ergonomic problems he encounters when using Prolog: the ISO notion of “strings” is inconsistent across implementations, the language lacks conventional functions and native boolean values, and the standard data model offers only lists and compound terms rather than maps or structs. He also describes how Prolog’s control features — depth-first search, the cut operator (!), and negation as failure (+) — can be difficult to reason about and lead to surprising behavior. Other pain points he highlights include symbol terms that map infix syntax to compound terms, the behavior of bagof and its N^ grouping operator, and that sort returns a duplicate-free sorted set rather than preserving duplicates. He contrasts Prolog with alternatives like Picat and notes he will add Answer Set Programming and Logic Constraint Programming material to the book.
Why it matters
- Language inconsistencies across implementations can hinder code portability and reuse.
- Missing language features (functions, booleans, maps) affect ergonomics and raise friction for general-purpose programming.
- Control primitives like cuts and negation as failure can produce subtle, hard-to-debug behavior.
- Design choices influence which logic programming systems (e.g., Picat, ASP) developers prefer for particular tasks.
Key facts
- The author is updating Logic for Programmers to include sections on Answer Set Programming and Logic Constraint Programming.
- ISO Prolog represents strings as atoms or lists of one-character atoms or integer codes; many implementations add incompatible string operators.
- Prolog uses predicates (rules) rather than functions; this supports bidirectionality but makes simple expressions like 'length+1' awkward.
- Standard Prolog lacks built-in key-value maps or struct types; common data forms are linked lists and compound terms.
- true and false in Prolog act as control outcomes rather than first-class boolean values; negation as failure (+) is used for negation.
- The cut operator (!) prevents backtracking and is useful for optimization but can make programs invalid or surprising if misused.
- bagof/3 collects alternatives into a list but requires explicit existential qualification (N^) to group free variables as expected.
- sort/2 in Prolog returns a sorted set (duplicates removed) rather than a sorted list that preserves duplicates; msort exists in many implementations.
- The author found a clunky but usable command-line invocation for running SWI-Prolog queries non-interactively: swipl -t halt -g "bagof(X, Goal, Xs), print(Xs)" ./file.pl.
What to watch next
- Release of the updated Logic for Programmers edition that includes sections on Answer Set Programming and Logic Constraint Programming (confirmed in the source).
- The author's upcoming writings about Answer Set Programming and how he integrates it into the book (confirmed in the source).
- Community responses, suggested workarounds, or counterarguments to these gripes and whether they lead to practice changes or tooling updates (not confirmed in the source).
Quick glossary
- Predicate: A basic Prolog construct expressing a relation or rule that can succeed or fail for given arguments.
- Cut (!): A control operator that prunes choice points to prevent backtracking past a certain point.
- Negation as Failure (+): A form of negation where + P succeeds if P cannot be proven; it is not the same as classical logical negation.
- bagof/3: A Prolog predicate that collects all solutions of a template into a list, with options to treat some variables existentially.
- Compound term: A data structure combining a functor and arguments (e.g., node(a,b)); often used instead of records or structs.
Reader FAQ
Will the author's book include material on Answer Set Programming?
Yes, the author says the next release will add sections on Answer Set Programming and Logic Constraint Programming.
Does Prolog have native boolean values true and false?
No; in Prolog true and false function as control outcomes rather than stored boolean values.
Are strings standardized and portable across Prolog implementations?
No; ISO Prolog represents strings as atoms or lists, and many implementations add incompatible string operators.
Does Prolog support functions in the usual sense?
Not in the conventional function sense; logic is expressed via predicates rather than functions.
Is it possible to sort a list while preserving duplicates in Prolog?
Some distributions provide msort for that purpose, but the standard sort/2 returns a duplicate-free sorted set.
January 14, 2026 My Gripes with Prolog It's not my favorite language For the next release of Logic for Programmers, I'm finally adding the sections on Answer Set Programming and…
Sources
Related posts
- Why Senior Engineers Let Bad Projects Fail: Managing Influence Wisely
- How I Learned Programming: Hands-On Practice, Community, and Curiosity
- Best alternatives to Spotify for streaming and listening to music