erg/doc/zh_TW/syntax/24_module.md
2022-09-06 20:13:44 +08: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

上一頁 | 下一頁