aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-01 11:59:41 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-01 11:59:41 +0300
commit992865e827cdfffa6451ca37e74f185c5228f894 (patch)
treebdf89ab4a26aed61ed429795edf192de90350efc
parent61b985db80a15e230476af54b0ef8783fd8cbf63 (diff)
downloadmyslip-992865e827cdfffa6451ca37e74f185c5228f894.tar.gz
myslip-992865e827cdfffa6451ca37e74f185c5228f894.zip
Modified quote so the values of lists are evaluated
-rw-r--r--src/sexp/mod.rs2
-rw-r--r--src/sexp/step.rs21
2 files changed, 22 insertions, 1 deletions
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<Self, String> {
match self {