From c477302c8867863641c114a89adf5623cc5fc744 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 21 Aug 2023 13:17:58 -0700 Subject: [PATCH] Fixed `ans` evaluation --- src/context.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 484d61b..c61444c 100644 --- a/src/context.rs +++ b/src/context.rs @@ -126,6 +126,7 @@ impl Context { } else { panic!() } } + // Can we define a new variable with this name? pub fn valid_varible(&self, s: &str) -> bool { if { Function::from_string(s).is_some() || @@ -145,10 +146,17 @@ impl Context { } } + // Can we get a value fro mthis variable name? pub fn is_varible(&self, s: &str) -> bool { return { - self.valid_varible(s) && - (self.variables.contains_key(s) || self.shadow.contains_key(s)) + ( + s == "ans" && + self.history.len() != 0 + ) || + ( + self.valid_varible(s) && + (self.variables.contains_key(s) || self.shadow.contains_key(s)) + ) }; }