summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud.bailly@iohk.io>2024-09-23 15:41:31 +0200
committerArnaud Bailly <arnaud.bailly@iohk.io>2024-09-23 15:41:31 +0200
commit402013e9e8b3366dd604d4abbe69b7585426c568 (patch)
treeee7aa3a32542c1e86c58c11069ce1da9ec2e9734 /rust/src
parent098968d1a8f39ab5eb670b7f5370817343a0f88f (diff)
downloadlambda-nantes-402013e9e8b3366dd604d4abbe69b7585426c568.tar.gz
Introduce symbols
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/lambda.rs10
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"));
+ }
}