Update docs

This commit is contained in:
Shunsuke Shibayama 2022-10-21 00:29:15 +09:00
parent e26a89c0b3
commit f1667f295e
4 changed files with 34 additions and 23 deletions

View file

@ -50,8 +50,9 @@ def baz():
class C:
...
...
```
````python
```python
# foo.d.er
.X: Int
.bar!: Int => Int

View file

@ -6,8 +6,8 @@ The entry point for the lib package is `src/lib.er`. Importing a package is equi
A package has a sub-structure called a module, which in Erg is an Erg file or directory composed of Erg files. External Erg files/directories are manipulatable objects as module objects.
In order for a directory to be recognized as a module, it is necessary to place a `(directory name).er` file in the directory.
This is similar to Python's `__init__.py`, but unlike `__init__.py`, it is placed outside the directory.
In order for a directory to be recognized as a module, a `__init__.er` file must be placed in the directory.
This is similar to `__init__.py` in Python.
As an example, consider the following directory structure.
@ -15,15 +15,15 @@ As an example, consider the following directory structure.
└─┬ ./src
├─ app.er
├─ foo.er
├─ bar.er
└─┬ bar
├─ __init__.er
├─ baz.er
└─ qux.er
```
You can import `foo` and `bar` modules in `app.er`. The `bar` directory can be recognized as a module because of the `bar.er` file.
In `app.er` you can import `foo` and `bar` modules. The `bar` directory can be recognized as a module because of the `__init__.er` file.
A `foo` module is a module consisting of files, and a `bar` module is a module consisting of directories. The `bar` module also contains `baz` and `qux` modules.
This module is simply an attribute of the `bar` module, and can be accessed from `app.er` as follows.
This module is simply an attribute of the `bar` module, and can be accessed from `app.er` as follows
```python
# app.er
@ -36,16 +36,16 @@ main args =
...
```
Note the `/` delimiter for accessing submodules. This is because there can be file names such as `bar.baz.er`.
Such filenames are discouraged, since the `.er` prefix is meaningful in Erg.
Note that the delimiter for accessing submodules is `/`. This is because a file name like `bar.baz.er` is possible.
However, such filenames are discouraged, because in Erg, the identifier immediately preceding the `.er`, the prefix, is meaningful.
For example, a module for testing. A file ending with `.test.er` is a (white box) test module, which executes a subroutine decorated with `@Test` when the test is run.
```console
└─┬ ./src
└─┬ . /src
├─ app.er
├─ foo.er
└─ foo.test.er
./src
```
```python
# app.er
@ -55,17 +55,22 @@ main args =
...
```
Also, files ending in ``.private.er`` are private modules and can only be accessed by modules in the same directory.
Also, modules that are not reimported in `__init__.er` are private modules and can only be accessed by modules in the same directory.
```console
└─┬
├─ foo.er
├─ bar.er
└─┬ bar
├─ baz.private.er
├─ __init__.er
├─ baz.er
└─ qux.er
```
```python
# __init__.py
.qux = import "qux" # this is public
```
```python
# foo.er
bar = import "bar"

View file

@ -5,7 +5,7 @@
## Pythonへのexport
Ergスクリプトをコンパイルすると.pycファイルが生成されますが、これは単純にPythonのモジュールとして読み込むことができます。
ただし、Erg側で非公開に設定した変数はPythonからアクセスできません。
ただし、Erg側で非公開に設定した変数はPythonからアクセスできません。
```python
# foo.er
@ -70,7 +70,7 @@ foo = pyimport "foo"
assert foo.bar!(1) in Int
```
これは、実行時に型チェックを行うことで型安全性を担保しています。チェック機構は概以下のように動作します。
これは、実行時に型チェックを行うことで型安全性を担保しています。チェック機構は概念的には以下のように動作します。
```python
decl_proc proc!: Proc, T =

View file

@ -8,8 +8,8 @@ libパッケージのエントリポイントは`src/lib.er`です。パッケ
パッケージにはモジュールという下位構造があります。Ergにおいてモジュールとはすなわち、Ergファイルもしくはそれで構成されたディレクトリです。外部のErgファイル/ディレクトリはモジュールオブジェクトとして操作可能な対象になるのです。
ディレクトリをモジュールとして認識させるには、ディレクトリ内に`(ディレクトリ名).er`ファイルを置く必要があります。
これはPythonの`__init__.py`と同じようなものですが、`__init__.py`と違ってディレクトリの外に置きます
ディレクトリをモジュールとして認識させるには、ディレクトリ内に`__init__.er`ファイルを置く必要があります。
これはPythonの`__init__.py`と同じようなものです。
例として、以下のようなディレクトリ構成を考えてみましょう。
@ -17,13 +17,13 @@ libパッケージのエントリポイントは`src/lib.er`です。パッケ
└─┬ ./src
├─ app.er
├─ foo.er
├─ bar.er
└─┬ bar
├─ __init__.er
├─ baz.er
└─ qux.er
```
`app.er`では`foo`モジュールと`bar`モジュールをインポートできます。`bar`ディレクトリがモジュールとして認識できるのは`bar.er`ファイルがあるためです。
`app.er`では`foo`モジュールと`bar`モジュールをインポートできます。`bar`ディレクトリがモジュールとして認識できるのは`__init__.er`ファイルがあるためです。
`foo`モジュールはファイルからなるモジュールで、`bar`モジュールはディレクトリからなるモジュールです。`bar`モジュールはさらに`baz`, `qux`モジュールを内部に持ちます。
このモジュールは単に`bar`モジュールの属性であり、`app.er`からは以下のようにアクセスできます。
@ -39,7 +39,7 @@ main args =
```
サブモジュールにアクセスするための区切り文字が`/`であることに注意してください。これは、`bar.baz.er`のようなファイル名があり得るためです。
このようなファイル名は推奨されません。Ergでは`.er`のプレフィックスが意味を持つためです。
しかしこのようなファイル名は推奨されません。Ergでは`.er`直前の識別子、プレフィックスが意味を持つためです。
例えば、テスト用のモジュールです。`.test.er`で終わるファイルは(ホワイトボックス)テスト用のモジュールであり、テスト実行時に`@Test`でデコレーションされたサブルーチンが実行されます。
```console
@ -57,17 +57,22 @@ main args =
...
```
また、`.private.er`で終わるファイルはプライベートモジュールであり、同一ディレクトリのモジュールからしかアクセスできません。
また、`__init__.er`内でre-importされていないモジュールはプライベートモジュールであり、同一ディレクトリのモジュールからしかアクセスできません。
```console
└─┬
├─ foo.er
├─ bar.er
└─┬ bar
├─ baz.private.er
├─ __init__.er
├─ baz.er
└─ qux.er
```
```python
# __init__.py
.qux = import "qux" # this is public
```
```python
# foo.er
bar = import "bar"