once/1 cuts caller choice points inconsistently across Prolog systems
0 reputation · 03 Jan 2026, 04:46 UTC
Goal
Use once/1 to guarantee that a write operation (e.g., assert/1) executes only once even when the surrounding predicate is retried via backtracking.
Constraints and uncertainty
The ISO core defines once/1 as a cut that removes choice points created inside the wrapped goal. However, implementations differ on whether that cut also removes choice points from the caller’s context. SWI‑Prolog treats it as a hard cut, while YAP historically uses a softer variant. This discrepancy can silently drop legitimate alternative solutions or, conversely, leave hidden choice points that cause duplicate writes.
Questions
- Does
once/1in SWI‑Prolog 9.x remove choice points created before the call? - How does YAP 6.2.2’s
once/1differ in choice‑point handling? - What portable pattern ensures a single write without sacrificing needed backtracking?