Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit 431f8ec

Browse files
authored
ex_01_options (#12)
* 翻訳開始 * 翻訳完了
1 parent 3026bb9 commit 431f8ec

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lean/extra/01_options.lean

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
/-
2+
--#--
23
# Extra: Options
4+
--#--
5+
# 付録:オプション
6+
--#--
37
Options are a way to communicate some special configuration to both
48
your meta programs and the Lean compiler itself. Basically it's just
59
a [`KVMap`](https://github.com/leanprover/lean4/blob/master/src/Lean/Data/KVMap.lean)
610
which is a simple map from `Name` to a `Lean.DataValue`. Right now there
711
are 6 kinds of data values:
12+
--#--
13+
オプションはメタプログラムと Lean のコンパイラの両方に特別な設定を伝える機能です。基本的にこれは [`KVMap`](https://github.com/leanprover/lean4/blob/master/src/Lean/Data/KVMap.lean) であり、`Name` から `Lean.DataValue` への単純なマップです。現在、6種類のデータ値を有します:
14+
815
- `String`
916
- `Bool`
1017
- `Name`
1118
- `Nat`
1219
- `Int`
1320
- `Syntax`
1421
22+
--#--
1523
Setting an option to tell the Lean compiler to do something different
1624
with your program is quite simple with the `set_option` command:
25+
--#--
26+
`set_option` コマンドを使うことで、とても簡単に Lean コンパイラにプログラムに対して何か違うことを行うように指示するオプションを設定することができます:
1727
-/
1828

1929
import Lean
@@ -28,7 +38,10 @@ set_option pp.explicit true -- No custom syntax in pretty printing
2838
set_option pp.explicit false
2939

3040
/-!
41+
--#--
3142
You can furthermore limit an option value to just the next command or term:
43+
--#--
44+
さらに、オプションの値をすぐ次のコマンドや項だけに限定することもできます:
3245
-/
3346

3447
set_option pp.explicit true in
@@ -39,24 +52,42 @@ set_option pp.explicit true in
3952
#check set_option trace.Meta.synthInstance true in 1 + 1 -- the trace of the type class synthesis for `OfNat` and `HAdd`
4053

4154
/-!
55+
--#--
4256
If you want to know which options are available out of the Box right now
4357
you can simply write out the `set_option` command and move your cursor
4458
to where the name is written, it should give you a list of them as auto
4559
completion suggestions. The most useful group of options when you are
4660
debugging some meta thing is the `trace.` one.
4761
62+
--#--
63+
もし今すぐ利用可能なオプションを取り出したい場合は、`set_option` コマンドを実行し、カーソルをその名前が書かれている場所に移動するだけで、自動補完の候補としてそれらのオプションのリストが表示されるでしょう。メタ関連でデバッグをしているときに最も役に立つオプションは `trace.` から始まるものです。
64+
65+
--#--
4866
## Options in meta programming
67+
--#--
68+
## メタプログラミングにおけるオプション
69+
--#--
4970
Now that we know how to set options, let's take a look at how a meta program
5071
can get access to them. The most common way to do this is via the `MonadOptions`
5172
type class, an extension to `Monad` that provides a function `getOptions : m Options`.
5273
As of now, it is implemented by:
74+
--#--
75+
これでオプションを設定する方法がわかったので、メタプログラムがオプションにアクセスする方法を見てみましょう。最も一般的な方法は `MonadOptions` 型クラスを通じたもので、これは `Monad` に関数 `getOptions : m Options` を拡張したものです。現時点でこれは以下に対して実装されています:
76+
5377
- `CoreM`
5478
- `CommandElabM`
5579
- `LevelElabM`
80+
--#--
5681
- all monads to which you can lift operations of one of the above (e.g. `MetaM` from `CoreM`)
5782
83+
--#--
84+
- 上記のいずれかの操作を持ち上げることができるすべてのモナド(例えば、`CoreM` から `MetaM`)
85+
86+
--#--
5887
Once we have an `Options` object, we can query the information via `Options.get`.
5988
To show this, let's write a command that prints the value of `pp.explicit`.
89+
--#--
90+
一度 `Options` オブジェクトを取得すれば、`Options.get` を使って情報を照会することができます。これを示すために、`pp.explicit` の値を表示するコマンドを書いてみましょう。
6091
-/
6192
elab "#getPPExplicit" : command => do
6293
let opts ← getOptions
@@ -69,12 +100,22 @@ set_option pp.explicit true in
69100
#getPPExplicit -- pp.explicit : true
70101

71102
/-!
103+
--#--
72104
Note that the real implementation of getting `pp.explicit`, `Lean.getPPExplicit`,
73105
uses whether `pp.all` is set as a default value instead.
74106
107+
--#--
108+
`pp.explicit` を取得するた実際の実装である `Lean.getPPExplicit` は代わりに `pp.all` がデフォルト値として設定されているかどうかを使用することに注意してください。
109+
110+
--#--
75111
## Making our own
112+
--#--
113+
## 独自のオプションを作る
114+
--#--
76115
Declaring our own option is quite easy as well. The Lean compiler provides
77116
a macro `register_option` for this. Let's see it in action:
117+
--#--
118+
独自のオプションを宣言するのも非常に簡単です。Lean コンパイラはこのために `register_option` というマクロを用意しています。実際に使ってみましょう:
78119
-/
79120

80121
register_option book.myGreeting : String := {
@@ -84,6 +125,9 @@ register_option book.myGreeting : String := {
84125
}
85126

86127
/-!
128+
--#--
87129
However, we cannot just use an option that we just declared in the same file
88130
it was declared in because of initialization restrictions.
131+
--#--
132+
しかし、初期化の制約があるため、宣言したオプションをそのまま同じファイルで使うことはできません。
89133
-/

md/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# 付録
2121

22-
- [Options](./extra/01_options.md)
22+
- [オプション](./extra/01_options.md)
2323
<!-- - [Attributes]() -->
2424
- [Pretty Printing](./extra/03_pretty-printing.md)
2525

0 commit comments

Comments
 (0)