From 34074287861b3ef6c9ee89195056d20ae1603cfc Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 26 Jul 2025 18:34:44 +0300 Subject: Added variables and tests for their substitution --- src/sexp/subst.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/sexp/subst.rs (limited to 'src/sexp/subst.rs') diff --git a/src/sexp/subst.rs b/src/sexp/subst.rs new file mode 100644 index 0000000..7cfa180 --- /dev/null +++ b/src/sexp/subst.rs @@ -0,0 +1,21 @@ + +use crate::sexp::{SExp, SExp::*, SLeaf::*, util::*}; + +impl SExp { + /// Performs substitution on the s-expression. + /// + /// Replaces all free occurrences of variables + /// named `name` with the given `value` + /// in this s-expression. + /// ```rust + /// use melisp::sexp::{SExp::*, SLeaf::*, util::*}; + /// + /// assert_eq!( + /// scons(Add, scons(var("a"), var("b"))).subst("b", scons(Sub, scons(2, 1))), + /// scons(Add, scons(var("a"), scons(Sub, scons(2, 1)))) + /// ); + /// ``` + pub fn subst(self, name: &str, value: SExp) -> SExp { + todo!(); + } +} -- cgit v1.2.3