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

Commit 63733d2

Browse files
authored
Files翻訳 (#30)
* 翻訳開始 * 翻訳完了
1 parent 17b0625 commit 63733d2

File tree

3 files changed

+181
-14
lines changed

3 files changed

+181
-14
lines changed

.github/workflows/label-pr.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ name: Label PRs with artifacts
55
# further actions.
66

77
on:
8-
workflow_run:
9-
workflows: ["Build and check HTML"]
10-
types:
11-
- completed
8+
workflow_dispatch:
9+
# workflow_run:
10+
# workflows: ["Build and check HTML"]
11+
# types:
12+
# - completed
1213

1314
jobs:
1415
label:

Manual/IO/Console.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In particular, to read a line from standard input, use a combination of {lean}`I
3131

3232
:::
3333

34-
Lean は {tech}[standard output] と {tech}[standard error] に書き出すための便利な関数を有しています。それらは全て {lean}`ToString` インスタンスを使用し、そのうち名前が `-ln` で終わるものは出力の後に改行を追加します。これらの便利な関数は {ref "stdio"}[標準 I/O ストリームを使用する] 機能の一部しか公開していません。特に、標準入力から行を読むには、 {lean}`IO.getStdin` と {lean}`IO.FS.Stream.getLine` を組み合わせて使用します。
34+
Lean は {tech}[標準出力] と {tech}[標準エラー] に書き出すための便利な関数を有しています。それらは全て {lean}`ToString` インスタンスを使用し、そのうち名前が `-ln` で終わるものは出力の後に改行を追加します。これらの便利な関数は {ref "stdio"}[標準 I/O ストリームを使用する] 機能の一部しか公開していません。特に、標準入力から行を読むには、 {lean}`IO.getStdin` と {lean}`IO.FS.Stream.getLine` を組み合わせて使用します。
3535

3636
{docstring IO.print}
3737

Manual/IO/Files.lean

Lines changed: 175 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,57 @@ set_option pp.rawOnError true
1818

1919
set_option linter.unusedVariables false
2020

21+
/-
2122
#doc (Manual) "Files, File Handles, and Streams" =>
23+
-/
24+
#doc (Manual) "ファイル・ファイルハンドラ・ストリーム(Files, File Handles, and Streams)" =>
2225

26+
:::comment
2327
Lean provides a consistent filesystem API on all supported platforms.
2428
These are the key concepts:
2529

30+
:::
31+
32+
Lean はサポート対象のすべてのプラットフォームに対して一貫したファイルシステム API を提供します。以下がカギとなるコンセプトです:
33+
34+
:::comment
2635
: {deftech}[Files]
2736

2837
Files are an abstraction provided by operating systems that provide random access to persistently-stored data, organized hierarchically into directories.
2938

39+
:::
40+
41+
: {deftech}[ファイル] (file)
42+
43+
ファイルとはオペレーティングシステムが提供する抽象化で、ディレクトリとして階層的に編成された永続的に保存されるデータへのランダムアクセスを提供します。
44+
45+
:::comment
3046
: {deftech}[Directories]
3147

3248
Directories, also known as _folders_, may contain files or other directories.
3349
Fundamentally, a directory maps names to the files and/or directories that it contains.
3450

51+
:::
52+
53+
: {deftech}[ディレクトリ] (directory)
54+
55+
ディレクトリは _フォルダ_ (folder)としても知られ、ファイルや他のディレクトリを含むことができます。基本的に、ディレクトリはその中に含まれるファイルやディレクトリに名前をマッピングします。
56+
57+
:::comment
3558
: {deftech}[File Handles]
3659

3760
File handles ({name IO.FS.Handle}`Handle`) are abstract references to files that have been opened for reading and/or writing.
3861
A file handle maintains a mode that determines whether reading and/or writing are allowed, along with a cursor that points at a specific location in the file.
3962
Reading from or writing to a file handle advances the cursor.
4063
File handles may be {deftech}[buffered], which means that reading from a file handle may not return the current contents of the persistent data, and writing to a file handle may not modify them immediately.
4164

65+
:::
66+
67+
: {deftech}[ファイルハンドラ] (file handler)
68+
69+
ファイルハンドラ( {name IO.FS.Handle}`Handle` )は読み書きのどちらか、もしくは両方のためにオープンされたファイルへの抽象的な参照です。ファイルハンドラはファイルの特定の場所を指すカーソルと共に、読み書きのどちらか、もしくは両方が許可されているかどうかを決定するモードを保持します。ファイルハンドラからの読み込みやファイルハンドラへの書き込みによってカーソルが進められます。ファイルハンドラは {deftech}[バッファ] される可能性があります。これはファイルハンドラからの読み込みが永続データの現在の内容を返さない可能性およびファイルハンドラへの書き込みが直ちに反映されない可能性があることを意味します。
70+
71+
:::comment
4272
: Paths
4373

4474
Files are primarily accessed via {deftech}_paths_ ({name}`System.FilePath`).
@@ -54,19 +84,46 @@ These are the key concepts:
5484
Extensions are delimited by the character {name}`System.FilePath.extSeparator`.
5585
On some platforms, executable files have a special extension ({name}`System.FilePath.exeExtension`).
5686

87+
:::
88+
89+
: パス
90+
91+
ファイルは主に {deftech}_パス_ (path、 {name}`System.FilePath` )を介してアクセスされます。パスはディレクトリ名の列で、ファイル名で終わる可能性があります。パスは名前を区切り文字 {margin}[現在のプラットフォームでの区切り文字は {name}`System.FilePath.pathSeparators` にリストされています。] で区切られた文字列として表現されます。
92+
93+
パスの詳細はプラットフォームに固有です。 {deftech}[絶対パス] (absolute path)は {deftech}_ルートディレクトリ_ (root directory)から始まります;いくつかのオペレーティングシステムでは単一のルートを持ちますが、それ以外では複数のルートディレクトリを持つ可能性があります。相対パスはルートディレクトリから始まらず、他のディレクトリを始点とする必要があります。ディレクトリに加えて、パスは特別なディレクトリ名 `.` を含むことができます。これは見つかったディレクトリを指します。また `..` はパス内の前のディレクトリを指します。
94+
95+
ファイル名、またパスはファイルの種類を識別する1つ以上の {deftech}_拡張子_ (extension)で終わることがあります。拡張子は {name}`System.FilePath.extSeparator` 文字で区切られます。一部のプラットフォームでは、実行ファイルは特別な拡張子( {name}`System.FilePath.exeExtension` )を持ちます。
96+
97+
:::comment
5798
: {deftech}[Streams]
5899

59100
Streams are a higher-level abstraction over files, both providing additional functionality and hiding some details of files.
60101
While {tech}[file handles] are essentially a thin wrapper around the operating system's representation, streams are implemented in Lean as a structure called {lean}`IO.FS.Stream`.
61102
Because streams are implemented in Lean, user code can create additional streams, which can be used seamlessly together with those provided in the standard library.
62103

104+
:::
105+
106+
: {deftech}[ストリーム] (stream)
107+
108+
ストリームはファイルをより高度に抽象化したもので、追加機能を提供しつつファイルの詳細を隠します。 {tech}[ファイルハンドラ] は基本的にオペレーティングシステムの表現の薄いラッパーですが、ストリームは Lean では {lean}`IO.FS.Stream` という構造体として実装されています。ストリームは Lean 上で実装されているため、ユーザコードは追加のストリームを作成することができ、標準ライブラリで提供されるストリームとシームレスに併用することができます。
109+
110+
:::comment
63111
# Low-Level File API
112+
:::
113+
114+
# 低レベルのファイル API(Low-Level File API)
64115

116+
117+
:::comment
65118
At the lowest level, files are explicitly opened using {name IO.FS.Handle.mk}`Handle.mk`.
66119
When the last reference to the handle object is dropped, the file is closed.
67120
There is no explicit way to close a file handle other than by ensuring that there are no references to it.
68121

69122

123+
:::
124+
125+
最も低いレベルでは、ファイルは {name IO.FS.Handle.mk}`Handle.mk` を使って明示的にオープンされます。ハンドラオブジェクトへの最後の参照が削除されると、ファイルはクローズされます。ファイルハンドラを閉じる明示的な方法は、そのハンドラへの参照がないことを確認する以外に存在しません。
126+
70127
{docstring IO.FS.Handle}
71128

72129
{docstring IO.FS.Handle.mk}
@@ -104,15 +161,23 @@ There is no explicit way to close a file handle other than by ensuring that ther
104161
{docstring IO.FS.Handle.unlock}
105162

106163

107-
::::example "One File, Multiple Handles"
164+
:::comment
165+
::example "One File, Multiple Handles"
166+
:::
167+
:::::example "1つのファイルと複数のハンドラ"
168+
:::comment
108169
This program has two handles to the same file.
109170
Because file I/O may be buffered independently for each handle, {name IO.FS.Handle.flush}`Handle.flush` should be called when the buffers need to be synchronized with the file's actual contents.
110171
Here, the two handles proceed in lock-step through the file, with one of them a single byte ahead of the other.
111172
The first handle is used to count the number of occurrences of `'A'`, while the second is used to replace each `'A'` with `'!'`.
112173
The second handle is opened in {name IO.FS.Mode.readWrite}`readWrite` mode rather than {name IO.FS.Mode.write}`write` mode because opening an existing file in {name IO.FS.Mode.write}`write` mode replaces it with an empty file.
113174
In this case, the buffers don't need to be flushed during execution because modifications occur only to parts of the file that will not be read again, but the write handle should be flushed after the loop has completed.
114175

115-
:::ioExample
176+
:::
177+
178+
このプログラムには同じファイルに対する2つのハンドラがあります。ファイル I/O はハンドラごとに独立してバッファされることがあるため、バッファをファイルの実際の内容と同期させる必要がある場合は {name IO.FS.Handle.flush}`Handle.flush` を呼び出す必要があります。ここでは2つのハンドラは一方のハンドラが他方のハンドラより1バイト先になるようにファイル内をロックステップで進みます。最初のハンドラは `'A'` の出現回数を数えるために使われ、2番目のハンドラは `'A'` を `'!'` に置き換えるために使われます。2番目のハンドラは {name IO.FS.Mode.write}`write` モードではなく {name IO.FS.Mode.readWrite}`readWrite` モードで開かれています。これは {name IO.FS.Mode.write}`write` モードで既存のファイルを開くと空のファイルに置き換わるからです。今回の場合、バッファは実行中にフラッシュされる必要はありません。なぜなら変更はファイルの再読み込みされない部分に対してのみ行われるものの、書き出しハンドラはループが完了したらフラッシュしなければならないからです。
179+
180+
::::ioExample
116181
```ioLean
117182
open IO.FS (Handle)
118183

@@ -139,12 +204,22 @@ def main : IO Unit := do
139204
IO.println s!"Contents: '{(← IO.FS.readFile "data").trim}'"
140205
```
141206

207+
:::comment
142208
When run on this file:
209+
:::
210+
211+
このファイルに対して実行すると:
212+
143213
```inputFile "data"
144214
AABAABCDAB
145215
```
146216

217+
:::comment
147218
the program outputs:
219+
:::
220+
221+
プログラムは以下を出力します:
222+
148223
```stdout
149224
Starting contents: 'AABAABCDAB'
150225
Count: 5
@@ -153,15 +228,25 @@ Contents: '!!B!!BCD!B'
153228
```stderr (show := false)
154229
```
155230

231+
:::comment
156232
Afterwards, the file contains:
233+
:::
234+
235+
その後、ファイル内容は以下のようになります:
236+
157237
```outputFile "data"
158238
!!B!!BCD!B
159239
```
160240

161-
:::
162241
::::
242+
:::::
163243

244+
:::comment
164245
# Streams
246+
:::
247+
248+
# ストリーム(Streams)
249+
165250

166251
{docstring IO.FS.Stream}
167252

@@ -179,20 +264,40 @@ Afterwards, the file contains:
179264

180265
{docstring IO.FS.Stream.Buffer.pos}
181266

267+
:::comment
182268
# Paths
269+
:::
270+
271+
# パス(Paths)
183272

273+
274+
:::comment
184275
Paths are represented by strings.
185276
Different platforms have different conventions for paths: some use slashes (`/`) as directory separators, others use backslashes (`\`).
186277
Some are case-sensitive, others are not.
187278
Different Unicode encodings and normal forms may be used to represent filenames, and some platforms consider filenames to be byte sequences rather than strings.
188279
A string that represents an {tech}[absolute path] on one system may not even be a valid path on another system.
189280

281+
:::
282+
283+
パスは文字列として表現されます。ディレクトリの区切り文字としてスラッシュ(`/`)を使う場合もあれば、バックスラッシュ(`\`)を使う場合もあります。大文字小文字を区別する場合もあれば区別しない場合もあります。ファイル名を表現するために異なる Unicode エンコーディングや正規形が使われるかもしれず、プラットフォームによってはファイル名を文字列ではなくバイト列とみなすものもあります。あるシステムでは {tech}[絶対パス] を表す文字列が別のシステムでは有効なパスではないこともあります。
284+
285+
:::comment
190286
To write Lean code that is as compatible as possible with multiple systems, it can be helpful to use Lean's path manipulation primitives instead of raw string manipulation.
191287
Helpers such as {name}`System.FilePath.join` take platform-specific rules for absolute paths into account, {name}`System.FilePath.pathSeparator` contains the appropriate path separator for the current platform, and {name}`System.FilePath.exeExtension` contains any necessary extension for executable files.
192288
Avoid hard-coding these rules.
193289

290+
:::
291+
292+
複数のシステムで可能な限り互換性のある Lean コードを書くには、生の文字列操作の代わりに Lean のパス操作プリミティブを使用すると便利です。 {name}`System.FilePath.join` のような補助関数は絶対パスのプラットフォーム固有の規則を考慮し、 {name}`System.FilePath.pathSeparator` は現在のプラットフォームに適切なパス区切り文字を保持し、 {name}`System.FilePath.exeExtension` は実行ファイルに必要な拡張子を保持します。これらの規則をハードコードすることは避けてください。
293+
294+
:::comment
194295
There is an instance of the {lean}`Div` type class for {name System.FilePath}`FilePath` which allows the slash operator to be used to concatenate paths.
195296

297+
:::
298+
299+
{name System.FilePath}`FilePath` の {lean}`Div` 型クラスのインスタンスがあり、スラッシュ演算子を使ってパスを連結することができます。
300+
196301
{docstring System.FilePath}
197302

198303
{docstring System.mkFilePath}
@@ -229,10 +334,20 @@ There is an instance of the {lean}`Div` type class for {name System.FilePath}`Fi
229334

230335
{docstring System.FilePath.exeExtension}
231336

337+
:::comment
232338
# Interacting with the Filesystem
339+
:::
233340

341+
# ファイルシステムの対話(Interacting with the Filesystem)
342+
343+
344+
:::comment
234345
Some operations on paths consult the filesystem.
235346

347+
:::
348+
349+
パスに対するいくつかの操作はファイルシステムを参照します。
350+
236351
{docstring IO.FS.Metadata}
237352

238353
{docstring System.FilePath.metadata}
@@ -285,27 +400,50 @@ Some operations on paths consult the filesystem.
285400

286401
{docstring IO.FS.createDir}
287402

403+
:::comment
288404
# Standard I/O
405+
:::
406+
407+
# 標準 I/O(Standard I/O)
408+
289409
%%%
290410
tag := "stdio"
291411
%%%
292412

413+
:::comment
293414
On operating systems that are derived from or inspired by Unix, {deftech}_standard input_, {deftech}_standard output_, and {deftech}_standard error_ are the names of three streams that are available in each process.
294415
Generally, programs are expected to read from standard input, write ordinary output to the standard output, and error messages to the standard error.
295416
By default, standard input receives input from the console, while standard output and standard error output to the console, but all three are often redirected to or from pipes or files.
296417

418+
:::
419+
420+
Unix から派生した、または Unix に影響を受けたオペレーティングシステムでは、各プロセスで利用可能な3つのストリームに {deftech}_標準入力_ (standard input)・ {deftech}_標準出力_ (standard output)・ {deftech}_標準エラー_ (standard エラー)の名前がついています。一般的に、プログラムは標準入力から読み、標準出力に通常の出力を書き、標準エラーにエラーメッセージを書き込むことが期待されています。デフォルトでは、標準入力はコンソールからの入力を受け取り、標準出力と標準エラーに出力を行いますが、3つともパイプやファイルにリダイレクトされることが多いです。
421+
422+
:::comment
297423
Rather than providing direct access to the operating system's standard I/O facilities, Lean wraps them in {name IO.FS.Stream}`Stream`s.
298424
Additionally, the {lean}`IO` monad contains special support for replacing or locally overriding them.
299425
This extra level of indirection makes it possible to redirect input and output within a Lean program.
300426

301427

428+
:::
429+
430+
Lean はオペレーティングシステムの標準 I/O 機能への直接アクセスを提供するのではなく、 {name IO.FS.Stream}`Stream` でラップしています。さらに、 {lean}`IO` モナドはそれらを置き換えたり、ローカルでオーバーライドするための特別なサポートを含んでいます。この特別なレベルのインダイレクトにより、Lean プログラム内で入出力をリダイレクトすることが可能になります。
431+
302432
{docstring IO.getStdin}
303433

304-
::::example "Reading from Standard Input"
434+
:::comment
435+
::example "Reading from Standard Input"
436+
:::
437+
:::::example "標準入力からの読み取り"
438+
:::comment
305439
In this example, {lean}`IO.getStdin` and {lean}`IO.getStdout` are used to get the current standard input and output, respectively.
306440
These can be read from and written to.
307441

308-
:::ioExample
442+
:::
443+
444+
この例では、 {lean}`IO.getStdin` と {lean}`IO.getStdout` がそれぞれ現在の標準入力と標準出力を取得するために使用されています。これらは読み込みと書き込みが可能です。
445+
446+
::::ioExample
309447
```ioLean
310448
def main : IO Unit := do
311449
let stdin ← IO.getStdin
@@ -316,17 +454,27 @@ def main : IO Unit := do
316454
stdout.putStrLn name
317455
```
318456

457+
:::comment
319458
With this standard input:
459+
:::
460+
461+
以下の標準入力に対して:
462+
320463
```stdin
321464
Lean user
322465
```
466+
:::comment
323467
the standard output is:
468+
:::
469+
470+
標準出力は以下のようになります:
471+
324472
```stdout
325473
Who is it?
326474
Hello, Lean user
327475
```
328-
:::
329476
::::
477+
:::::
330478

331479
{docstring IO.setStdin}
332480

@@ -346,11 +494,19 @@ Hello, Lean user
346494

347495
{docstring IO.FS.withIsolatedStreams}
348496

349-
::::keepEnv
350-
:::example "Redirecting Standard I/O to Strings"
497+
:::::keepEnv
498+
:::comment
499+
::example "Redirecting Standard I/O to Strings"
500+
:::
501+
::::example "標準 I/O から文字列へのリダイレクト"
502+
:::comment
351503
The {lean}`countdown` function counts down from a specified number, writing its progress to standard output.
352504
Using `IO.FS.withIsolatedStreams`, this output can be redirected to a string.
353505

506+
:::
507+
508+
509+
354510
```lean (name := countdown)
355511
def countdown : Nat → IO Unit
356512
| 0 =>
@@ -366,14 +522,24 @@ def runCountdown : IO String := do
366522
#eval runCountdown
367523
```
368524

525+
:::comment
369526
Running {lean}`countdown` yields a string that contains the output:
527+
:::
528+
529+
{lean}`countdown` を実行すると、出力を含む文字列が得られます:
530+
370531
```leanOutput countdown
371532
"10\n9\n8\n7\n6\n5\n4\n3\n2\n1\nBlastoff!\n"
372533
```
373-
:::
374534
::::
535+
:::::
375536

537+
:::comment
376538
# Files and Directories
539+
:::
540+
541+
# ファイルとディレクトリ(Files and Directories)
542+
377543

378544
{docstring IO.currentDir}
379545

0 commit comments

Comments
 (0)