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