aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/step.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-26 10:52:03 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-07-26 10:52:03 +0300
commitbf4632c461508de5202db98d25cd7ec06787c8dd (patch)
treedab8ddb1b0dcb7a20b9ab2e7067e26344776db4c /src/sexp/step.rs
parentc810925fce7d5de1845e09538b6943f54f266cb0 (diff)
downloadmyslip-bf4632c461508de5202db98d25cd7ec06787c8dd.tar.gz
myslip-bf4632c461508de5202db98d25cd7ec06787c8dd.zip
Created necessary data structures and utilities for integers and their operations; added tests for them
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r--src/sexp/step.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
new file mode 100644
index 0000000..86ad9ea
--- /dev/null
+++ b/src/sexp/step.rs
@@ -0,0 +1,49 @@
+
+use crate::sexp::SExp;
+
+impl SExp {
+
+ /// Evaluates the s-expression one step.
+ ///
+ /// **Integer operations**
+ ///
+ /// Addition, subtraction, multiplication and division
+ /// are supported.
+ /// ```rust
+ /// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
+ ///
+ /// assert_eq!(
+ /// sexp(Add, sexp(1, 1)).step().unwrap(),
+ /// Atom(Int(2))
+ /// );
+ ///
+ /// assert_eq!(
+ /// sexp(Sub, sexp(1, 2).step().unwrap()),
+ /// Atom(Int(-1))
+ /// );
+ ///
+ /// assert_eq!(
+ /// sexp(Mul, sexp(2, 3).step().unwrap()),
+ /// Atom(Int(6))
+ /// );
+ ///
+ /// assert_eq!(
+ /// sexp(Div, sexp(6, 2).step().unwrap()),
+ /// Atom(Int(3))
+ /// );
+ /// ```
+ ///
+ /// Division truncates the decimals.
+ /// ```rust
+ /// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
+ ///
+ /// assert_eq!(
+ /// sexp(Div, sexp(5, 2).step().unwrap()),
+ /// Atom(Int(2))
+ /// );
+ ///
+ /// ```
+ pub fn step(self) -> Result<Self, String> {
+ todo!();
+ }
+}