Working example

This commit is contained in:
2023-03-10 13:58:16 +00:00
parent 35a081162f
commit 180ebb56fa
62 changed files with 1487 additions and 372 deletions

43
src/external/bool/ifthenelse.rs vendored Normal file
View File

@@ -0,0 +1,43 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use crate::external::assertion_error::AssertionError;
use crate::representations::PathSet;
use crate::{atomic_impl, atomic_redirect, externfn_impl};
use crate::representations::interpreted::Clause;
use super::Boolean;
/// IfThenElse function
///
/// Next state: [IfThenElse0]
#[derive(Clone)]
pub struct IfThenElse1;
externfn_impl!(IfThenElse1, |_: &Self, c: Clause| {Ok(IfThenElse0{c})});
/// Partially applied IfThenElse function
///
/// Prev state: [IfThenElse1]; Next state: [IfThenElse0]
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct IfThenElse0{ c: Clause }
atomic_redirect!(IfThenElse0, c);
atomic_impl!(IfThenElse0, |this: &Self| {
let Boolean(b) = (&this.c).try_into()
.map_err(|_| AssertionError::ext(this.c.clone(), "a boolean"))?;
Ok(if b { Clause::Lambda {
args: Some(PathSet { steps: Rc::new(vec![]), next: None }),
body: Rc::new(Clause::Lambda {
args: None,
body: Rc::new(Clause::LambdaArg)
})
}} else { Clause::Lambda {
args: None,
body: Rc::new(Clause::Lambda {
args: Some(PathSet { steps: Rc::new(vec![]), next: None }),
body: Rc::new(Clause::LambdaArg)
})
}})
});