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

構造体(structure)のフィールドを部分的に更新するdo構文を作る。macro_rules コマンド使用例

Open
#1,201 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

Zulip: notation for unpacking structures and field assignment

mkIdentFrom などの良い使用例になっている。本文で紹介するためには、私が実装の詳細をきちんと理解する必要がある。

import Lean

open Lean Parser

macro_rules
| `(doElem| $x:ident := $val) => do
  let .str n f := x.getId | Macro.throwUnsupported
  if n == .anonymous then Macro.throwUnsupported
  let o := mkIdentFrom x n
  let field := mkIdentFrom x (Name.mkSimple f)
  `(doElem| $o:ident := {$o with $field:ident := $val})

#guard show Bool from Id.run do
  let mut s := (1,2)
  s.fst := 3
  s == (3, 2)

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

Start with the linked Zulip discussion and the shown macro_rules example, then inspect the uses of mkIdentFrom and the #guard example. Document this partial structure-field update do syntax in the relevant book section, including the macro_rules usage. Done when the implementation details and runnable example are clearly explained.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.