From 6c38d9b13b8e1cc976f9b22d15d100fd03ee54d4 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 3 Aug 2019 13:49:17 +0800 Subject: Reuse ans output and fix tests --- src/lex/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lex') diff --git a/src/lex/mod.rs b/src/lex/mod.rs index cac16ca..caafd4b 100644 --- a/src/lex/mod.rs +++ b/src/lex/mod.rs @@ -122,7 +122,7 @@ fn factorial (n: f64) -> f64 { n.signum() * (1.. n.abs() as u64 +1).fold(1, |p, n| p*n) as f64 } -pub fn lexer(input: &str, prev_ans: &mut f64) -> Result, CalcError> { +pub fn lexer(input: &str, prev_ans: f64) -> Result, CalcError> { let functions: HashMap<&str, Token> = get_functions(); let operators: HashMap = get_operators(); @@ -159,7 +159,7 @@ pub fn lexer(input: &str, prev_ans: &mut f64) -> Result, CalcError> { num_vec.clear(); } last_char_is_op = false; - result.push(Token::Num(*prev_ans)); + result.push(Token::Num(prev_ans)); } 'a'...'z' | 'A'...'Z' => { let parse_num = num_vec.parse::().ok(); -- cgit v1.2.3