summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/lambda.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs
index b05bd22..9b2a6f2 100644
--- a/rust/src/lambda.rs
+++ b/rust/src/lambda.rs
@@ -17,7 +17,14 @@ pub fn run(arg: &str) -> String {
fn interpret(arg: &Value) -> Value {
match arg {
- Value::App(l, r) => apply(&interpret(l), &interpret(r)),
+ Value::App(l, r) => {
+ let result = apply(&interpret(l), &interpret(r));
+ if result == *arg {
+ result
+ } else {
+ interpret(&result)
+ }
+ }
other => other.clone(),
}
}
@@ -94,4 +101,10 @@ mod lambda_test {
assert_eq!(Value::Num(12), interpret(&value));
}
+ #[test]
+ fn reduction_is_applied_until_normal_form_is_reached() {
+ let value = parse("((((lam y (lam x (lam y (x y)))) 13) (lam x x)) 11)");
+ assert_eq!(Value::Num(11), interpret(&value));
+ }
+
}