prolog-conventionslisted
Install: claude install-skill dougransom/prolog-agent-toolkit
# Portable ISO Prolog Conventions
Guidelines for writing clean, portable Prolog code aiming for standard ISO compliance subject to target engine limitations.
## Core Guidelines
1. **Logical Purity**: Prefer pure predicates. Avoid unnecessary side effects, negation-as-failure `\+/1`, or non-deterministic cuts `!` where pure logic constructs (`dif/2`, `if_/3`) can be used. Prefer `dif(X, Y)` over `\+ (X = Y)` for sound term inequality.
2. **Strings as Character Lists (`chars`)**: Represent strings and text as lists of characters (`chars`). `double_quotes` must always be set to `chars`.
3. **Safe Type Testing**: Prefer pure, safe type tests (e.g. `library(si)`: `list_si/1`, `atom_si/1`, `chars_si/1`, `integer_si/1`) over impure non-monotonic type checks (`is_list/1`).
4. **Higher-Order Logic & Lambdas**: Use higher-order predicates (`call/N`, `call//N`, `maplist/N`, `foldl/N`, `include/3`, `exclude/3`) and `library(lambda)` (`\X^...`, `\X^Y^Goal`) to eliminate code repetition.
5. **Standard & Higher-Order DCGs**: Use Definite Clause Grammars (`-->`) for sequence parsing, formatting, and tree transformations. Use `call//N` for higher-order DCG non-terminals.
6. **Explicit Library Declarations**: Always explicitly import required library modules (e.g. `:- use_module(library(dcgs)).`, `:- use_module(library(charsio)).`, `:- use_module(library(lambda)).`, `:- use_module(library(clpz)).`). Do not assume SWI-style autoloading when targeting ISO or embedded engines.
7. **Control Str