From: bakaq Date: Mon, 30 Sep 2024 02:21:18 +0000 (-0300) Subject: LeafAnswer docs and success checking methods X-Git-Tag: v0.10.0~92^2~20 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=1375f448a04adbfd2c41db113e8acf0ff429f2ef;p=scryer-prolog.git LeafAnswer docs and success checking methods --- diff --git a/src/machine/parsed_results.rs b/src/machine/parsed_results.rs index 3688bc97..ec3d4693 100644 --- a/src/machine/parsed_results.rs +++ b/src/machine/parsed_results.rs @@ -14,15 +14,47 @@ use super::{HeapCellValue, Number}; /// Represents a leaf answer from a query. #[derive(Debug, Clone, PartialEq, Eq)] pub enum LeafAnswer { + /// A `true` leaf answer. True, + /// A `false` leaf answer. + /// + /// This means that there are no more answers for the query. False, + /// An exception leaf answer. Exception(PrologTerm), + /// A leaf answer with bindings and residual goals. + /// + /// Both bindings and residual goals can be empty. LeafAnswer { bindings: BTreeMap, residual_goals: Vec, }, } +impl LeafAnswer { + /// True if leaf answer failed. + /// + /// This gives [`false`] for exceptions. + pub fn failed(&self) -> bool { + match self { + LeafAnswer::False => true, + _ => false, + } + } + + /// True if leaf answer may have succeeded. + /// + /// When a leaf answer has residual goals the success is conditional on the satisfiability of + /// the contraints they represent. This gives [`false`] for exceptions. + pub fn maybe_succeeded(&self) -> bool { + match self { + LeafAnswer::True => true, + LeafAnswer::LeafAnswer { .. } => true, + _ => false, + } + } +} + /// Represents a Prolog term. #[non_exhaustive] #[derive(Debug, Clone, PartialEq, Eq)]