mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
44 lines
1.3 KiB
Markdown
44 lines
1.3 KiB
Markdown
# モジュール
|
|
|
|
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/syntax/24_module.md&commit_hash=06f8edc9e2c0cee34f6396fd7c64ec834ffb5352)
|
|
|
|
Ergでは、ファイル自体を1つのレコードとみなすことができます。これをモジュールと呼びます。
|
|
|
|
```python: foo.er
|
|
# foo.er
|
|
.i = 1
|
|
```
|
|
|
|
```python
|
|
# fooモジュールを定義するのはこのレコードを定義するのとほとんど同じ
|
|
foo = {.i = 1}
|
|
```
|
|
|
|
```python: bar.er
|
|
# bar.er
|
|
foo = import "foo"
|
|
print! foo # <module 'foo'>
|
|
assert foo.i == 1
|
|
```
|
|
|
|
モジュール型はレコード型でもあるので、分解代入が可能です。
|
|
|
|
```python
|
|
{sin; cos; ...} = import "math"
|
|
```
|
|
|
|
## モジュールの可視性
|
|
|
|
```console
|
|
└─┬ ./src
|
|
├─ lib.er
|
|
├─ foo.er
|
|
├─ bar.er
|
|
└─┬ bar
|
|
├─ baz.er
|
|
└─ qux.er
|
|
```
|
|
|
|
<p align='center'>
|
|
<a href='./23_closure.md'>Previous</a> | <a href='./25_object_system.md'>Next</a>
|
|
</p>
|