Zulip Chat Archive
Stream: lean4
Topic: Minimally commenting out a branch of a proof
Geoffrey Irving (Jan 02 2024 at 15:41):
If I put a sorry
at the beginning of a block of a proof, any following tactic statements produce errors. Is there a variant of sorry
that would be silent, to allow quickly commenting out a branch (in particular to save time during proving)?
Example that I would like to work
import Mathlib
lemma simple : 7 = 7 := by
sorryVariant
norm_num -- I'd like this not to produce an error
Johan Commelin (Jan 02 2024 at 15:43):
In Lean 3 you could do sorry { tac1, tac2 }
. We should get that to work again.
Geoffrey Irving (Jan 02 2024 at 15:44):
Having to add the { }
doesn't look as nice alongside Lean 4's indentation style, though.
Ruben Van de Velde (Jan 02 2024 at 15:47):
Use stop
instead
Geoffrey Irving (Jan 02 2024 at 15:50):
Perfect, terrific that it already exists!
Patrick Massot (Jan 02 2024 at 15:56):
I didn't know either, and the implementation looks like a miraculous hack to me.
Patrick Massot (Jan 02 2024 at 15:57):
But it makes sense when you think of it.
Patrick Massot (Jan 02 2024 at 15:59):
The miracle clears up with https://github.com/leanprover/std4/blob/main/Std/Linter/UnreachableTactic.lean#L35-L38. This stop tactic is actually special-cased by the unreachable tactic linter.
Patrick Massot (Jan 02 2024 at 16:00):
Now it completely makes sense.
Patrick Massot (Jan 02 2024 at 16:01):
For people who are curious but not curious enough to track it down, the implementation of stop
is in core Lean, it says:
macro "stop" tacticSeq : tactic => `(tactic| repeat sorry)
Patrick Massot (Jan 02 2024 at 16:03):
So stop
consumes a sequence of tactics (this is the tacticSeq
) so the parser eats up every following tactics (without triggering the unreachable tactic linter, this was the confusing part until I looked at the linter implementation) and replaces them with repeat sorry
.
Patrick Massot (Jan 02 2024 at 16:05):
@Marc Huisinga It would be nice to get stop
syntax-highlighted the same way sorry
is.
Alex J. Best (Jan 02 2024 at 16:18):
stop
is already marked as leanSorryLike
semantically https://github.com/leanprover/lean4/blob/cc1dcf804359276f0f7e8a673c04b2a2b7d69951/src/Lean/Server/FileWorker/RequestHandling.lean#L424. So I have
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {"leanSorryLike": "#FF0000"},
},
in my vscode settings to acheive this
Patrick Massot (Jan 02 2024 at 16:23):
And indeed it works!
Geoffrey Irving (Jan 02 2024 at 17:03):
Hmm, it doesn't work like I was hoping, though. If I do
lemma simple : 7 = 7 ∧ 5 = 5 := by
constructor
· stop
·
and put my cursor after the second ·
, it says No goals
. Though it also says
unsolved goals
case right
⊢ 5 = 5
Patrick Massot (Jan 02 2024 at 17:09):
Maybe a better implementation would be macro "stop" (colGe tacticSeq)? : tactic => `(tactic| repeat sorry)
? @Sebastian Ullrich
Alex J. Best (Jan 02 2024 at 17:11):
I think you'd need to use sorry for that example? but stop if there are other following tactics indeed
Geoffrey Irving (Jan 02 2024 at 17:12):
Hmm, so stop requires a nonzero number of following tactics?
Alex J. Best (Jan 02 2024 at 17:16):
Well it always eats a tacticSeq, which could be empty, but in this case I think it's matching your second .
as the following tacticSeq, which Patrick's version should avoid
Ruben Van de Velde (Jan 02 2024 at 17:16):
That's a little odd. stop; done
works as intended
Last updated: May 02 2025 at 03:31 UTC