-
Notifications
You must be signed in to change notification settings - Fork 441
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
RFC: add the option to add a prefix and a suffix to a doc-string when using inherit_doc
#2622
Comments
@adomani, I don't think this belongs in core. Is there any reason it can't go in Std? |
@semorrison, I was simply going by what I thought that Mario had suggested in the Zulip chat. I do not mind if it goes in Std or core, though. |
@semorrison Yes, this has to be implemented in core, because |
This PR is related to [Issue leanprover/lean4#2622](leanprover/lean4#2622). In the file where declaration `decl` is defined, writing ```lean extend_doc decl before "I will be added as a prefix to the docs of `decl`" after "I will be added as a suffix to the docs of `decl`" ``` does what is probably clear: it extends the doc-string of `decl` by adding the string immediately following `before` at the beginning and the string immediately following`after` at the end. This is useful, for instance, when the docs of `decl` are obtained via `inherit_doc`. [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/tactic.20docstrings) By way of example, I redefine the docs over `rw`. The new doc-string is ```lean `rw` is like `rewrite` (see below), but also tries to close the goal by "cheap" (reducible) `rfl` afterwards. `rewrite [e]` applies identity `e` as a rewrite rule to the target of the main goal. If `e` is preceded by left arrow (`←` or `<-`), the rewrite is applied in the reverse direction. If `e` is a defined constant, then the equational theorems associated with `e` are used. This provides a convenient way to unfold `e`. - `rewrite [e₁, ..., eₙ]` applies the given rules sequentially. - `rewrite [e] at l` rewrites `e` at location(s) `l`, where `l` is either `*` or a list of hypotheses in the local context. In the latter case, a turnstile `⊢` or `|-` can also be used, to signify the target of the goal. Using `rw (config := {occs := .pos L}) [e]`, where `L : List Nat`, you can control which "occurrences" are rewritten. (This option applies to each rule, so usually this will only be used with a single rule.) Occurrences count from `1`. At the first occurrence, whether allowed or not, arguments of the rewrite rule `e` may be instantiated, restricting which later rewrites can be found. `{occs := .neg L}` allows skipping specified occurrences. ```
Instead of extending |
Proposal
Currently,
@[inherit_doc foo] def bar ...
copies the doc-string offoo
tobar
.The proposal is to add the option of extending the docs of
foo
by prefixing and suffixing extra strings.Here is a sample usage
User Experience: This allows to copy over docs from "parent" declarations and highlight how children differ from their parents.
Beneficiaries: The proposal arose from discussions in
Mathlib
. Relevant Zulip thread.Maintainability: I have no expertise in answering this question, but my naive impression is that it would not require much maintenance.
Community Feedback
The Zulip thread mentioned above originated from the current doc-string for
rw
, which mentionsrewrite
but not whatrw
actually does.With the current proposal, the docs for
rw
could be inherited fromrewrite
, preceded with the sentence that is currently the doc-string forrw
.Impact
Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: