erg/doc/zh_CN/syntax/24_module.md
2022-09-06 09:29:14 +09:00

1.2 KiB

module

badge

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

上一页 | 下一页