lean-ja / lean-ja/lean-by-example

マクロ衛生に関して、生の識別子を導入する方法

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

Nobody has claimed this yet.

オプション メタプログラミング 宣言的コマンド
Dominant language
Lean
Stars
188
Forks
15
Avg merge
9h 8m
Merged PRs (30d)
6

Description

-- マクロ衛生を保つ機能のために、マクロで定義した識別子にアクセスできない例
section

macro "#introcue" : command => `(def foo := 1)

#introcue

-- マクロ衛生のために、マクロ内で導入された識別子の名前が自動的に変更されるので、
-- foo にはアクセスできない
#check_failure foo

-- mkIdent という関数を使うと、マクロ衛生を保つ機能を潜り抜けて生の識別子を導入できる
macro "#introcue'" : command => `(def $(Lean.mkIdent `foo) := 1)

#introcue'

-- foo にアクセスできる!!!!
#check foo

end

Contributor guide

Open the contributing guide

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

No target file or test is named. Start by reviewing the macro-hygiene examples in the issue, especially #introcue and #introcue', then determine where this explanation belongs and document how Lean.mkIdent introduces a raw identifier; done means the example clearly explains both behaviors.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.