Skip to content
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

Merged
merged 2 commits into from
Dec 14, 2017
Merged

Conversation

billpmurphy
Copy link
Contributor

@billpmurphy billpmurphy commented Dec 14, 2017

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.

Copy link
Owner

@ljedrz ljedrz left a 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)
Copy link
Owner

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
Copy link
Owner

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 {
Copy link
Owner

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));
Copy link
Owner

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

@ljedrz ljedrz merged commit 4f62d20 into ljedrz:master Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants