Zulip Chat Archive
Stream: lean4
Topic: elab with tactics
louq (Sep 06 2024 at 02:36):
Im figuring out how to use elab
elab "process_all_goals" : tactic => do
let goal_type ← Lean.Elab.Tactic.getMainTarget
let glctx <- Lean.MonadLCtx.getLCtx
I want to use tactics during elaboration. Is there a way for this?
Leni Aniva (Sep 06 2024 at 02:39):
louq said:
Im figuring out how to use elab
elab "process_all_goals" : tactic => do let goal_type ← Lean.Elab.Tactic.getMainTarget let glctx <- Lean.MonadLCtx.getLCtx
I want to use tactics during elaboration. Is there a way for this?
you can run the TacticM
monad inside of your Elab.TermM
monad
let tacticM : TacticM := do
...
tacticM.run { elaborator := .anonymous } |>.run { goals := [goal] }
louq (Sep 06 2024 at 02:48):
can you give me an example
Leni Aniva (Sep 06 2024 at 03:19):
louq said:
can you give me an example
do you mean an example of running TacticM
inside Elab.TermM
?
louq (Sep 06 2024 at 11:08):
yes.
Kyle Miller (Sep 06 2024 at 17:23):
Maybe you're looking for docs#Lean.Elab.Tactic.evalTactic ?
If you want to construct a proof from a tactic script, you could also do elabTermEnsuringType (<- `(by my_tactics)) goal_type
. That's docs#Lean.Elab.Tactic.elabTermEnsuringType
Leni Aniva (Sep 06 2024 at 23:25):
louq said:
yes.
def runTacticM (mvarId: MVarId) (tactic: Elab.Tactic.TacticM Unit): Elab.TermElabM (List MVarId) := do
mvarId.checkNotAssigned `runTacticM
let (_, newGoals) ← tacticM { elaborator := .anonymous } |>.run { goals := [mvarId] }
return newGoals
like this?
louq (Sep 07 2024 at 17:11):
Leni Aniva said:
louq said:
yes.
def runTacticM (mvarId: MVarId) (tactic: Elab.Tactic.TacticM Unit): Elab.TermElabM (List MVarId) := do mvarId.checkNotAssigned `runTacticM let (_, newGoals) ← tacticM { elaborator := .anonymous } |>.run { goals := [mvarId] } return newGoals
like this?
Im using lean4 web version. Can you show me the use of this in lean4?
Last updated: May 02 2025 at 03:31 UTC