diff --git a/Readme.org b/Readme.org index d354564..aa0c0a6 100644 --- a/Readme.org +++ b/Readme.org @@ -210,7 +210,7 @@ Will need a concatenate function for tables **** DONE mul **** DONE exp **** DONE mod -***** TODO Test for Let Destructuring +***** DONE Test for Let Destructuring **** TODO inc **** TODO dec **** TODO gt? diff --git a/src/stl/math.rs b/src/stl/math.rs index 017547f..c1c3e44 100644 --- a/src/stl/math.rs +++ b/src/stl/math.rs @@ -25,7 +25,8 @@ fn isnumeric(arg: &Ctr) -> bool { } } -pub const ADD_DOCSTRING: &str = "traverses over N args, which must all evaluate to an Integer or Float. +pub const ADD_DOCSTRING: &str = + "traverses over N args, which must all evaluate to an Integer or Float. Adds each arg up to a final result. WARNING: does not acocunt for under/overflows. Consult source code for a better understanding of how extreme values will be handled."; @@ -55,7 +56,7 @@ Consult source code for a better understanding of how extreme values will be han pub fn sub_callback(ast: &Seg, _: &mut SymTable) -> Result { if !isnumeric(&*ast.car) { - return Err(format!("{} is not a number", &*ast.car)) + return Err(format!("{} is not a number", &*ast.car)); } let mut res = *ast.car.clone(); let mut culprit: Ctr = Ctr::None; @@ -80,7 +81,6 @@ pub fn sub_callback(ast: &Seg, _: &mut SymTable) -> Result { } } - pub const DIV_DOCSTRING: &str = "takes two args, which must both evaluate to an Integer or Float. divides arg1 by arg2. WARNING: does not acocunt for under/overflows or float precision. Consult source code for a better understanding of how extreme values will be handled."; @@ -102,7 +102,8 @@ pub fn div_callback(ast: &Seg, _: &mut SymTable) -> Result { } } -pub const MUL_DOCSTRING: &str = "traverses over N args, which must all evaluate to an Integer or Float. +pub const MUL_DOCSTRING: &str = + "traverses over N args, which must all evaluate to an Integer or Float. Multiplies each arg up to a final result. WARNING: does not acocunt for under/overflows. Consult source code for a better understanding of how extreme values will be handled."; @@ -178,7 +179,7 @@ PANIC CASES: - an integer is rased to the power of another integer exceeding the max size of an unsigned 32bit integer"; pub fn exp_callback(ast: &Seg, _: &mut SymTable) -> Result { - let first = *ast.car.clone(); + let first = *ast.car.clone(); if !isnumeric(&first) { return Err("first argument must be numeric".to_string()); } @@ -218,7 +219,7 @@ PANIC CASES: "; pub fn mod_callback(ast: &Seg, _: &mut SymTable) -> Result { - let first = *ast.car.clone(); + let first = *ast.car.clone(); if !isnumeric(&first) { return Err("first argument must be numeric".to_string()); } @@ -239,27 +240,27 @@ pub fn mod_callback(ast: &Seg, _: &mut SymTable) -> Result { Ctr::Float(rf) => { ret.append(Box::new(Ctr::Integer((lf / rf) as i128))); ret.append(Box::new(Ctr::Integer((lf % rf) as i128))); - }, + } Ctr::Integer(ri) => { ret.append(Box::new(Ctr::Integer((lf / ri as f64) as i128))); ret.append(Box::new(Ctr::Integer((lf % ri as f64) as i128))); - }, + } _ => return Err("mod not implemented for these arguments".to_string()), }, Ctr::Integer(li) => match second { Ctr::Float(rf) => { ret.append(Box::new(Ctr::Integer((li as f64 / rf) as i128))); - ret.append(Box::new(Ctr::Integer((li as f64 % rf) as i128))); }, + ret.append(Box::new(Ctr::Integer((li as f64 % rf) as i128))); + } Ctr::Integer(ri) => { ret.append(Box::new(Ctr::Integer(li / ri))); ret.append(Box::new(Ctr::Integer(li % ri))); - }, + } _ => return Err("mod not implemented for these arguments".to_string()), }, _ => return Err("mod not implemented for these arguments".to_string()), } - Ok(Ctr::Seg(ret)) } diff --git a/tests/test_lib_math.rs b/tests/test_lib_math.rs index 6811532..98b0963 100644 --- a/tests/test_lib_math.rs +++ b/tests/test_lib_math.rs @@ -258,7 +258,8 @@ mod math_lib_tests { fn test_fi_mod() { let document = "(def test '' (mod 7.2 2))"; let check1 = "(car test)"; - let result1 = "3"; let mut syms = SymTable::new(); + let result1 = "3"; + let mut syms = SymTable::new(); static_stdlib(&mut syms).unwrap(); dynamic_stdlib(&mut syms).unwrap(); let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();