1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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!();
}
}
|