aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/step.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r--src/sexp/step.rs61
1 files changed, 38 insertions, 23 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
index a6ce664..4391bb9 100644
--- a/src/sexp/step.rs
+++ b/src/sexp/step.rs
@@ -13,23 +13,23 @@ impl SExp {
/// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
///
/// assert_eq!(
- /// scons(Add, scons(1, 1)).step().unwrap(),
- /// Atom(Int(2))
+ /// scons(Add, scons(1, scons(1, Nil))).step(),
+ /// Ok(Atom(Int(2)))
/// );
///
/// assert_eq!(
- /// scons(Sub, scons(1, 2)).step().unwrap(),
- /// Atom(Int(-1))
+ /// scons(Sub, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(Int(-1)))
/// );
///
/// assert_eq!(
- /// scons(Mul, scons(2, 3)).step().unwrap(),
- /// Atom(Int(6))
+ /// scons(Mul, scons(2, scons(3, Nil))).step(),
+ /// Ok(Atom(Int(6)))
/// );
///
/// assert_eq!(
- /// scons(Div, scons(6, 2)).step().unwrap(),
- /// Atom(Int(3))
+ /// scons(Div, scons(6, scons(2, Nil))).step(),
+ /// Ok(Atom(Int(3)))
/// );
/// ```
///
@@ -38,33 +38,48 @@ impl SExp {
/// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
///
/// assert_eq!(
- /// scons(Div, scons(5, 2)).step().unwrap(),
- /// Atom(Int(2))
+ /// scons(Div, scons(5, scons(2, Nil))).step(),
+ /// Ok(Atom(Int(2)))
/// );
+ /// ```
+ ///
+ /// Also, addition and multiplication can take more than two arguments:
+ /// ```rust
+ /// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
///
+ /// assert_eq!(
+ /// scons(Add, scons(1, scons(2, scons(3, Nil)))).step(),
+ /// Ok(Atom(Int(6)))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Mul, scons(1, scons(2, scons(3, Nil)))).step(),
+ /// Ok(Atom(Int(6)))
+ /// );
/// ```
///
- /// Here's an example of a bit more complicated expression:
+ /// Here's an example of a bit more complicated expression
+ /// from wikipedias article on s-expressions.
/// ```rust
/// use melisp::sexp::{SExp::*, SLeaf::*, util::*};
///
/// fn main() {
- /// let exp = scons(Mul, scons(
- /// 2,
- /// scons(Add, scons(
- /// scons(Div, scons(5, 2)),
- /// 4
- /// ))
- /// ));
- ///
- /// let exp = exp.step().unwrap();
- /// assert_eq!(exp, scons(Mul, scons(2, scons(Add, scons(2, 4)))));
+ /// let exp = scons(
+ /// Mul,
+ /// scons(
+ /// 2,
+ /// scons(
+ /// scons(Add, scons(3, scons(4, Nil))),
+ /// Nil
+ /// )
+ /// )
+ /// );
///
/// let exp = exp.step().unwrap();
- /// assert_eq!(exp, scons(Mul, scons(2, 6)));
+ /// assert_eq!(exp, scons(Mul, scons(2, scons(7, Nil))));
///
/// let exp = exp.step().unwrap();
- /// assert_eq!(exp, Atom(Int(12)));
+ /// assert_eq!(exp, Atom(Int(14)));
/// }
///
/// ```