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:
@@ -40,6 +40,15 @@ impl TCO {
|
||||
args: Box::new(Self::transform(Rc::new((**args).clone()), false)),
|
||||
},
|
||||
|
||||
BoundKind::Again { args } => {
|
||||
if !is_tail_position {
|
||||
panic!("'again' is only allowed in tail position to avoid dead code.");
|
||||
}
|
||||
BoundKind::Again {
|
||||
args: Box::new(Self::transform(Rc::new((**args).clone()), false)),
|
||||
}
|
||||
}
|
||||
|
||||
BoundKind::If {
|
||||
cond,
|
||||
then_br,
|
||||
|
||||
Reference in New Issue
Block a user