diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-25 08:17:09 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-25 08:17:09 +0200 |
| commit | bb16c10c4c851018ee5aa905a719abdfd8fdc861 (patch) | |
| tree | 1a8ec26c53fd1f69f823fb6ce8359b3ca97d9bb2 /rust | |
| parent | d3781941c182fdc2971bac09b33b273e46232b00 (diff) | |
| download | lambda-nantes-bb16c10c4c851018ee5aa905a719abdfd8fdc861.tar.gz | |
Evaluate terms recursively on application
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/lambda.rs | 15 |
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)); + } + } |
