leanprover-community / leanprover-community/lean4-metaprogramming-book

Tactic chapter/FAQ: add creation of a fresh unique name

Open
#166 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
310
Forks
78
Avg merge
5h 37m
Merged PRs (30d)
5

Description

Proposal:

Add the following q&a to the FAQ:

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the tactic chapter/FAQ and read the surrounding entries to match its formatting and organization. Add the proposed question, answer, and Lean example, then verify that the FAQ explains fresh unique names and that the example demonstrates creating, using, and clearing the hypothesis.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.