-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add is_supercombinator to Term #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice; just one typo in a comment, a few nitpicks and it's good to go
src/term.rs
Outdated
/// ``` | ||
/// use lambda_calculus::term::*; | ||
/// | ||
/// let term1 = abs(app(Var(1), abs(Var(1)))); // λ 1 (λ 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment has an error - it should be λ 1 (λ 1)
src/term.rs
Outdated
@@ -288,6 +288,36 @@ impl Term { | |||
pub fn rhs_mut(&mut self) -> Result<&mut Term, TermError> { | |||
if let Ok((_, rhs)) = self.unapp_mut() { Ok(rhs) } else { Err(NotApp) } | |||
} | |||
|
|||
/// Returns `true` if and only if the lambda term is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking: I'd drop "and only if"
src/term.rs
Outdated
let mut stack = Vec::new(); | ||
stack.push((0, self)); | ||
while let Some((depth, term)) = stack.pop() { | ||
match term { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking again: match *term
src/term.rs
Outdated
/// ``` | ||
pub fn is_supercombinator(&self) -> bool { | ||
let mut stack = Vec::new(); | ||
stack.push((0, self)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will probably never be an issue in practice, but 0
is inferred as i32
here; it would be a good idea to annotate it as 0usize
Unrelated to 2.0.0 API changes, I think this is useful.
I wrote a naive recursive implementation for comparison; this naive iterative version is about 2x faster. Not sure if it's worth adding a warning to the documentation indicating that this function has to traverse the entire
Term
.