diff options
Diffstat (limited to 'rust/src/lambda.rs')
| -rw-r--r-- | rust/src/lambda.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index 7601640..ccb8c28 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -14,6 +14,7 @@ pub fn run(arg: &str) -> String { pub enum Value { Num(i32), Bool(bool), + Sym(String), } impl Display for Value { @@ -21,6 +22,7 @@ impl Display for Value { match self { Value::Num(i) => write!(f, "{}", i), Value::Bool(b) => write!(f, "{}", b), + Value::Sym(s) => write!(f, "{}", s), } } } @@ -29,7 +31,7 @@ fn interpret(arg: &str) -> Value { arg.parse::<i32>() .map(Value::Num) .or(arg.parse::<bool>().map(Value::Bool)) - .unwrap() + .unwrap_or(Value::Sym(arg.to_string())) } #[cfg(test)] @@ -46,9 +48,15 @@ mod tests { } } + #[test] fn interpret_truth_values_as_booleans() { assert_eq!(Bool(true), interpret("true")); assert_eq!(Bool(false), interpret("false")); } + + #[test] + fn interpret_identifiers_values_as_symbols() { + assert_eq!(Sym("foo".to_string()), interpret("foo")); + } } |
