Add 'again' keyword for recursive calls
The `again` keyword is introduced to facilitate explicit recursive function calls. It is restricted to tail-call positions to prevent dead code and ensure TCO optimization. Type checking is enhanced to validate argument types against function parameters.
This commit is contained in:
@@ -263,6 +263,15 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "'again' is only allowed in tail position to avoid dead code.")]
|
||||
fn test_again_non_tail_panic() {
|
||||
let env = Environment::new();
|
||||
let source = "(do (def f (fn [x] (do (again [(- x 1)]) x))) (f 5))";
|
||||
// This will trigger the TCO pass which contains the validation logic
|
||||
let _ = env.run_script(source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_call_destructuring_underflow() {
|
||||
let env = Environment::new();
|
||||
|
||||
Reference in New Issue
Block a user