Guide to avoiding common Prolog anti-patterns: cut (!/0), global state via assertz/retract, impure I/O, and low-level arithmetic predicates.
Key Takeaways
Using !/0, (->)/2, or var/1 causes lost solutions; replacing them with dif/2, if_/3, and clean data structures restores monotonicity.
assertz/1/retract/1 introduce implicit global state; thread state through predicate arguments or semicontext notation instead.
Printing answers via format/2 inside predicates breaks testability and generality; let the toplevel handle output.
Low-level arithmetic (is/2, =:=/2, >/2) forces simultaneous learning of declarative and operational semantics; CLP(FD) constraints remove that burden.
The n_factorial example shows that replacing ! and is/2 with CLP(FD) (#>/2, #=/2) enables the most general query to enumerate all solutions.
Hacker News Comment Review
Discussion is thin; no substantive technical debate about the specific constructs or declarative alternatives covered in the source.
One commenter questions whether Prolog has real-world relevance beyond academia; another dismisses the concerns as overblown, but neither engages with the CLP(FD) or purity arguments.
Notable Comments
@appil: Questions practical real-world use of Prolog outside university courses.
@crustycoder: “Mostly overblown” – no elaboration on which specific points.