1
1
/-
2
+ --#--
2
3
# Extra: Options
4
+ --#--
5
+ # 付録:オプション
6
+ --#--
3
7
Options are a way to communicate some special configuration to both
4
8
your meta programs and the Lean compiler itself. Basically it's just
5
9
a [ `KVMap` ] (https://github.com/leanprover/lean4/blob/master/src/Lean/Data/KVMap.lean)
6
10
which is a simple map from `Name` to a `Lean.DataValue`. Right now there
7
11
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
+
8
15
- `String`
9
16
- `Bool`
10
17
- `Name`
11
18
- `Nat`
12
19
- `Int`
13
20
- `Syntax`
14
21
22
+ --#--
15
23
Setting an option to tell the Lean compiler to do something different
16
24
with your program is quite simple with the `set_option` command:
25
+ --#--
26
+ `set_option` コマンドを使うことで、とても簡単に Lean コンパイラにプログラムに対して何か違うことを行うように指示するオプションを設定することができます:
17
27
-/
18
28
19
29
import Lean
@@ -28,7 +38,10 @@ set_option pp.explicit true -- No custom syntax in pretty printing
28
38
set_option pp.explicit false
29
39
30
40
/-!
41
+ --#--
31
42
You can furthermore limit an option value to just the next command or term:
43
+ --#--
44
+ さらに、オプションの値をすぐ次のコマンドや項だけに限定することもできます:
32
45
-/
33
46
34
47
set_option pp.explicit true in
@@ -39,24 +52,42 @@ set_option pp.explicit true in
39
52
#check set_option trace.Meta.synthInstance true in 1 + 1 -- the trace of the type class synthesis for `OfNat` and `HAdd`
40
53
41
54
/-!
55
+ --#--
42
56
If you want to know which options are available out of the Box right now
43
57
you can simply write out the `set_option` command and move your cursor
44
58
to where the name is written, it should give you a list of them as auto
45
59
completion suggestions. The most useful group of options when you are
46
60
debugging some meta thing is the `trace.` one.
47
61
62
+ --#--
63
+ もし今すぐ利用可能なオプションを取り出したい場合は、`set_option` コマンドを実行し、カーソルをその名前が書かれている場所に移動するだけで、自動補完の候補としてそれらのオプションのリストが表示されるでしょう。メタ関連でデバッグをしているときに最も役に立つオプションは `trace.` から始まるものです。
64
+
65
+ --#--
48
66
## Options in meta programming
67
+ --#--
68
+ ## メタプログラミングにおけるオプション
69
+ --#--
49
70
Now that we know how to set options, let's take a look at how a meta program
50
71
can get access to them. The most common way to do this is via the `MonadOptions`
51
72
type class, an extension to `Monad` that provides a function `getOptions : m Options`.
52
73
As of now, it is implemented by:
74
+ --#--
75
+ これでオプションを設定する方法がわかったので、メタプログラムがオプションにアクセスする方法を見てみましょう。最も一般的な方法は `MonadOptions` 型クラスを通じたもので、これは `Monad` に関数 `getOptions : m Options` を拡張したものです。現時点でこれは以下に対して実装されています:
76
+
53
77
- `CoreM`
54
78
- `CommandElabM`
55
79
- `LevelElabM`
80
+ --#--
56
81
- all monads to which you can lift operations of one of the above (e.g. `MetaM` from `CoreM`)
57
82
83
+ --#--
84
+ - 上記のいずれかの操作を持ち上げることができるすべてのモナド(例えば、`CoreM` から `MetaM`)
85
+
86
+ --#--
58
87
Once we have an `Options` object, we can query the information via `Options.get`.
59
88
To show this, let's write a command that prints the value of `pp.explicit`.
89
+ --#--
90
+ 一度 `Options` オブジェクトを取得すれば、`Options.get` を使って情報を照会することができます。これを示すために、`pp.explicit` の値を表示するコマンドを書いてみましょう。
60
91
-/
61
92
elab "#getPPExplicit" : command => do
62
93
let opts ← getOptions
@@ -69,12 +100,22 @@ set_option pp.explicit true in
69
100
#getPPExplicit -- pp.explicit : true
70
101
71
102
/-!
103
+ --#--
72
104
Note that the real implementation of getting `pp.explicit`, `Lean.getPPExplicit`,
73
105
uses whether `pp.all` is set as a default value instead.
74
106
107
+ --#--
108
+ `pp.explicit` を取得するた実際の実装である `Lean.getPPExplicit` は代わりに `pp.all` がデフォルト値として設定されているかどうかを使用することに注意してください。
109
+
110
+ --#--
75
111
## Making our own
112
+ --#--
113
+ ## 独自のオプションを作る
114
+ --#--
76
115
Declaring our own option is quite easy as well. The Lean compiler provides
77
116
a macro `register_option` for this. Let's see it in action:
117
+ --#--
118
+ 独自のオプションを宣言するのも非常に簡単です。Lean コンパイラはこのために `register_option` というマクロを用意しています。実際に使ってみましょう:
78
119
-/
79
120
80
121
register_option book.myGreeting : String := {
@@ -84,6 +125,9 @@ register_option book.myGreeting : String := {
84
125
}
85
126
86
127
/-!
128
+ --#--
87
129
However, we cannot just use an option that we just declared in the same file
88
130
it was declared in because of initialization restrictions.
131
+ --#--
132
+ しかし、初期化の制約があるため、宣言したオプションをそのまま同じファイルで使うことはできません。
89
133
-/
0 commit comments