mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
1.2 KiB
1.2 KiB
module
Erg allows you to think of the file itself as a single record. This is called a module.
# foo.er
.i = 1
# 定義 foo 模塊與定義這條記錄幾乎相同
foo = {.i = 1}
#bar.er
foo = import "foo"
print! foo # <module 'foo'>
assert foo.i == 1
由于模塊類型也是記錄類型,因此可以進行解構賦值
{sin; cos; ...} = import "math"
模塊可見性
└─┬ ./src
├─ lib.er
├─ foo.er
├─bar.er
└─┬ bar
├─ baz.er
└─ qux.er