Merged
Conversation
* Introduce `Context` to define free variables for parsing and display * Add `parse_with_context` to to resolve free variables based on a `Context` * Add `Term::with_context` for displaying terms using a given `Context`
ljedrz
reviewed
Sep 11, 2025
ljedrz
reviewed
Sep 11, 2025
Owner
ljedrz
left a comment
There was a problem hiding this comment.
Yeah, I think this feature is long overdue in this repo; would you like to fix the clippy warnings and consider one suggestion I've left?
Thanks!
Accepting a slice is more flexible and idiomatic than a vector reference (@ljedrz) Co-authored-by: ljedrz <3750347+ljedrz@users.noreply.github.com>
ce708a6 to
1f59337
Compare
Contributor
Author
|
@ljedrz While I was at it, I also fixed a couple of other pre-existing lints in unrelated code (b8a8145, 1f59337), following the "Boy Scout Rule". These additional cleanups are not essential to this PR, so if you'd prefer a more focused commit history, I am perfectly happy to revert them. Just let me know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Our current implementation of Term doesn't have free variable names as it is only a De Bruijn index expression, which is not correct. Free variable names are critical for open terms.
The issue is demonstrated by the following test, where free variable names were lost completely:
lambda_calculus/tests/reduction.rs
Line 62 in c961a86
This PR introduces a naming Context to give names to free variables, which is the same approach as the TAPL book.
Notes
A key inspiration for this change is the original TAPL implementation, which uses a top-level syntax to define variables (see https://github.com/mspertus/TAPL/blob/main/untyped/test.f ). In that implementation, you first have to define a variable like
x(usingx/;), which pushesxinto the naming context. Then, you can usexas a free variable.Since our implementation does not have such a top-level syntax, this PR introduces a Context type instead, which must be prepared manually by the user.