feat: light-weight basic quotation macro #241
Open
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.
Description:
I finally got annoyed enough at the lack of Qq, that I figured we can just roll our own basic version to get 80% of the benefits. So, I implemented a very basic
ql(..)
macro. Crucially, we only attempt to deal with closed terms, so we avoid a lot of the complexity that QQ has to deal with anti-quotations. Similarly, we avoid the performance problems of QQ because we don't attempt to deal with expression matching either.To implement the macro, we had to take the
ToExpr Expr
instance from Mathlib, which meant pulling in the ToExpr derive handler (which isn't a bad thing, that derive handler will be generally useful). That is,DeriveToExpr.lean
,ToExpr.lean
andToLevel.lean
are taken from Mathlib, with only very slight modifications to eliminate any further Mathlib dependencies to do with pretty-printing.Then,
Tactics/QuoteLight.lean
is actually new code. The implementation of theql(..)
macro is quite simple, only about 50 lines of meta-code. The rest of the file consists of a few basic tests.Even with this limited scope, the macro will be useful to simplify a bunch of our meta-code, removing some of the tedium involved and improving readability. For example, we currently have
mkApp (.const ``List.nil [0]) (mkConst ``StateField)
somewhere in the code, with the macro we can simplify this toql(@List.nil StateField)
.Testing:
What tests have been run? Did
make all
succeed for your changes? Wasconformance testing successful on an Aarch64 machine? Yes
License:
By submitting this pull request, I confirm that my contribution is
made under the terms of the Apache 2.0 license.