From ad9f7e6a689c7fe42444cbe22ecdf1de8d092d5b Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Fri, 26 Jun 2020 21:12:16 -0500 Subject: Evaluate basic arithmetic. --- src/lib/sexpr.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/lib/sexpr.rs') diff --git a/src/lib/sexpr.rs b/src/lib/sexpr.rs index 0d37332..a6fbe49 100644 --- a/src/lib/sexpr.rs +++ b/src/lib/sexpr.rs @@ -1,7 +1,45 @@ use super::types::Type; -pub enum SEXP { +#[derive(PartialEq, Debug)] +pub enum SExpr { Atom(Type), - List(Vec) + Sexpr(Vec) } +#[test] +fn construct() { + let atom1 = SExpr::Atom(Type::Number(Number::Int(1))); + let atom2 = SExpr::Atom(Type::Number(Number::Int(2))); + let atom3 = SExpr::Atom(Type::Number(Number::Int(3))); + let atom4 = SExpr::Atom(Type::Number(Number::Int(4))); + let sexp = SExpr::Sexpr(vec!(atom1, atom2, atom3, atom4)); + match sexp { + SExpr::Sexpr(ref x) => { + assert_eq!(x[0], SExpr::Atom(Type::Number(Number::Int(1)))); + }, + _ => panic!("What") + } +} + +#[test] +fn mutability() { + let atom1 = SExpr::Atom(Type::Number(Number::Int(1))); + let atom2 = SExpr::Atom(Type::Number(Number::Int(2))); + let atom3 = SExpr::Atom(Type::Number(Number::Int(3))); + let atom4 = SExpr::Atom(Type::Number(Number::Int(4))); + let mut sexp = SExpr::Sexpr(vec!(atom1, atom2, atom3, atom4)); + match sexp { + SExpr::Sexpr(ref mut x) => match x[0] { + SExpr::Atom(Type::Number(Number::Int(ref mut x))) => *x += 7, + _ => panic!("What") + }, + _ => panic!("What") + } + + match sexp { + SExpr::Sexpr(ref x) => { + assert_eq!(x[0], SExpr::Atom(Type::Number(Number::Int(8)))); + }, + _ => panic!("What") + } +} -- cgit v1.2.3