forked from Orchid/orchid
bug fixes and performance improvements
This commit is contained in:
26
src/external/str/concatenate.rs
vendored
26
src/external/str/concatenate.rs
vendored
@@ -1,11 +1,9 @@
|
||||
use super::cls2str;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::external::litconv::with_str;
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::{Primitive, Literal};
|
||||
use crate::representations::interpreted::Clause;
|
||||
use crate::representations::interpreted::{Clause, ExprInst};
|
||||
|
||||
/// Concatenate function
|
||||
///
|
||||
@@ -13,29 +11,29 @@ use crate::representations::interpreted::Clause;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Concatenate2;
|
||||
externfn_impl!(Concatenate2, |_: &Self, c: Clause| {Ok(Concatenate1{c})});
|
||||
externfn_impl!(Concatenate2, |_: &Self, c: ExprInst| {Ok(Concatenate1{c})});
|
||||
|
||||
/// Partially applied Concatenate function
|
||||
///
|
||||
/// Prev state: [Concatenate2]; Next state: [Concatenate0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Concatenate1{ c: Clause }
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Concatenate1{ c: ExprInst }
|
||||
atomic_redirect!(Concatenate1, c);
|
||||
atomic_impl!(Concatenate1);
|
||||
externfn_impl!(Concatenate1, |this: &Self, c: Clause| {
|
||||
let a: String = cls2str(&this.c)?.clone();
|
||||
Ok(Concatenate0{ a, c })
|
||||
externfn_impl!(Concatenate1, |this: &Self, c: ExprInst| {
|
||||
with_str(&this.c, |a| Ok(Concatenate0{ a: a.clone(), c }))
|
||||
});
|
||||
|
||||
/// Fully applied Concatenate function.
|
||||
///
|
||||
/// Prev state: [Concatenate1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Concatenate0 { a: String, c: Clause }
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Concatenate0 { a: String, c: ExprInst }
|
||||
atomic_redirect!(Concatenate0, c);
|
||||
atomic_impl!(Concatenate0, |Self{ a, c }: &Self| {
|
||||
let b: &String = cls2str(c)?;
|
||||
Ok(Clause::P(Primitive::Literal(Literal::Str(a.to_owned() + b))))
|
||||
with_str(c, |b| Ok(Clause::P(Primitive::Literal(
|
||||
Literal::Str(a.to_owned() + b)
|
||||
))))
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user