From 992865e827cdfffa6451ca37e74f185c5228f894 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Fri, 1 Aug 2025 11:59:41 +0300 Subject: Modified quote so the values of lists are evaluated --- src/sexp/mod.rs | 2 +- src/sexp/step.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index f6c50d7..71e62e9 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -39,7 +39,7 @@ use SLeaf::*; impl SExp { pub fn is_value(&self) -> bool { match self { - SCons(a, _) => **a == Atom(Quote), + SCons(a, b) => **a == Atom(Quote) && b.consists_of_values(), Atom(Var(_)) => false, Atom(_) => true, } diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 0989ee3..765e33c 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -83,6 +83,27 @@ impl SExp { /// } /// /// ``` + /// + /// **Quotes** + /// If an s-expression should not be evaluated + /// as a function, but it is instead to be treated + /// as a list, `quote` can be used. + /// With it as the operator, the rest of the list + /// is evaluated to values, but they are not passed + /// to the operator after that. + /// ```rust + /// use melisp::sexp::{SExp::*, SLeaf::*, util::*}; + /// assert_eq!( + /// scons(Quote, scons(1, scons(2, Nil))).step(), + /// Ok(scons(Quote, scons(1, scons(2, Nil)))) + /// ); + /// assert_eq!( + /// scons(Quote, scons( + /// scons(Sub, scons(2, scons(1, Nil))), + /// scons(2, Nil))).step(), + /// Ok(scons(Quote, scons(1, scons(2, Nil)))) + /// ); + /// ``` pub fn step(self) -> Result { match self { -- cgit v1.2.3