Skip to content

add creation of a fresh unique name #167

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lean/main/09_tactics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,36 @@ elab "faq_throw_error" : tactic =>
-- tactic 'faq_throw_error' failed, throwing an error at the current goal
-- ⊢ ∀ (b : Bool), b = true

/-!
/-
**Q: What is the difference between `Lean.Elab.Tactic.*` and `Lean.Meta.Tactic.*`?**

A: `Lean.Meta.Tactic.*` contains low level code that uses the `Meta` monad to
implement basic features such as rewriting. `Lean.Elab.Tactic.*` contains
high-level code that connects the low level development in `Lean.Meta` to the
tactic infrastructure and the parsing front-end.

**Q: How do I create a fresh unique name?**

A: Use `Lean.Core.mkFreshUserName <name-basis>`.

This creates a new (unused) inaccessible name based on name-basis. -/

elab " faq_fresh_hyp_name " : tactic =>
Lean.Elab.Tactic.withMainContext do
-- create fresh name based on name `h`
let h := Lean.mkIdent (← Lean.Core.mkFreshUserName `h)
-- create new hypothesis with this fresh name
Lean.Elab.Tactic.evalTactic (← `(tactic| have $h : 1 + 1 = 2 := by simp))
-- use hypothesis
Lean.Elab.Tactic.evalTactic (← `(tactic| rewrite [$h:ident]))
-- remove hypothesis
Lean.Elab.Tactic.evalTactic (← `(tactic| clear $h))

example : 1 + 1 = 2 := by
faq_fresh_hyp_name
rfl

/-!
## Exercises

1. Consider the theorem `p ∧ q ↔ q ∧ p`. We could either write its proof as a proof term, or construct it using the tactics.
Expand Down