diff --git a/README.md b/README.md
index 49367b2e6..68a09f913 100644
--- a/README.md
+++ b/README.md
@@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
- AttributeError: Array object has no attribute `.push!`
+ AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
- hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
- hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
+ hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
+ hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```
## Requirements
diff --git a/README_JA.md b/README_JA.md
index 88b5f88a5..ab8eb8c9d 100644
--- a/README_JA.md
+++ b/README_JA.md
@@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
- AttributeError: Arrayオブジェクトは`.push!`という属性を持っていません
+ AttributeError: Listオブジェクトは`.push!`という属性を持っていません
ヒント: オブジェクトの内部状態を変更したい場合は、`!`演算子を使って可変化してください
- ヒント: `Array`は`push`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/Array/##push を参照してください
- ヒント: `Array!`は`push!`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/Array!/##push! を参照してください
+ ヒント: `List`は`push`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/List/##push を参照してください
+ ヒント: `List!`は`push!`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/List!/##push! を参照してください
```
## Requirements
diff --git a/README_zh-CN.md b/README_zh-CN.md
index 1964bcffc..d926fd3a5 100644
--- a/README_zh-CN.md
+++ b/README_zh-CN.md
@@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
- AttributeError: Array object has no attribute `.push!`
+ AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
- hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
- hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
+ hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
+ hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```
## 要求
diff --git a/README_zh-TW.md b/README_zh-TW.md
index fec7a3077..6f00d2ade 100644
--- a/README_zh-TW.md
+++ b/README_zh-TW.md
@@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
- AttributeError: Array object has no attribute `.push!`
+ AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
- hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
- hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
+ hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
+ hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```
## 要求
diff --git a/TODO.md b/TODO.md
index 7a3be8907..125c497e8 100644
--- a/TODO.md
+++ b/TODO.md
@@ -21,7 +21,7 @@
* [ ] Pattern-matching
* [x] Variable Pattern
* [x] Literal Pattern
- * [x] Array Pattern
+ * [x] List Pattern
* [x] Tuple Pattern
* [x] Record Pattern
* [x] Data Type Pattern
@@ -30,7 +30,7 @@
* [x] Positional arguments
* [x] Keyword arguments
* [x] Variable length arguments
- * [x] Array literal
+ * [x] List literal
* [x] Record literal
* [x] Set literal
* [x] Dict literal
@@ -58,11 +58,11 @@
* [ ] Patch definition
* [ ] Glue Patch definition
* [x] Range object
- * [ ] Decorator
+ * [x] Decorator
* [ ] Comprehension
- * [ ] Array
- * [ ] Dict
- * [ ] Set
+ * [x] List
+ * [x] Dict
+ * [x] Set
* [ ] Tuple
* [x] Pipeline operator
* [ ] ? operator
@@ -91,7 +91,7 @@
* [x] `sys` (partially)
* [x] `time` (partially)
* [x] Load User Module
- * [ ] Recursive module
+ * [x] Recursive module
* [x] Visibility check
* [x] Patching
* [ ] Implement a side-effect checker
diff --git a/crates/els/call_hierarchy.rs b/crates/els/call_hierarchy.rs
index c1ec12d19..599b5550d 100644
--- a/crates/els/call_hierarchy.rs
+++ b/crates/els/call_hierarchy.rs
@@ -3,7 +3,7 @@ use std::str::FromStr;
use erg_compiler::artifact::BuildRunnable;
use erg_compiler::erg_parser::parse::Parsable;
-use erg_compiler::hir::{Accessor, Array, Def, Dict, Expr, KeyValue, Set, Tuple};
+use erg_compiler::hir::{Accessor, Def, Dict, Expr, KeyValue, List, Set, Tuple};
use erg_compiler::varinfo::{AbsLocation, VarInfo};
use lsp_types::{
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
@@ -145,8 +145,8 @@ impl
- Previous | Next
+ Previous | Next
{
debug_call_info!(self);
let l_sqbr = expect_pop!(self, fail_next LSqBr);
let inner = self
- .try_reduce_array_elems()
+ .try_reduce_list_elems()
.map_err(|_| self.stack_dec(fn_name!()))?;
let r_sqbr = expect_pop!(self, fail_next RSqBr);
- let arr = match inner {
- ArrayInner::Normal(mut elems) => {
+ let lis = match inner {
+ ListInner::Normal(mut elems) => {
let elems = if elems
.pos_args()
.first()
@@ -2896,21 +2896,21 @@ impl Parser {
} else {
elems
};
- Array::Normal(NormalArray::new(l_sqbr, r_sqbr, elems))
+ List::Normal(NormalList::new(l_sqbr, r_sqbr, elems))
}
- ArrayInner::WithLength(elem, len) => {
- Array::WithLength(ArrayWithLength::new(l_sqbr, r_sqbr, elem, len))
+ ListInner::WithLength(elem, len) => {
+ List::WithLength(ListWithLength::new(l_sqbr, r_sqbr, elem, len))
}
- ArrayInner::Comprehension {
+ ListInner::Comprehension {
layout,
generators,
guard,
- } => Array::Comprehension(ArrayComprehension::new(
+ } => List::Comprehension(ListComprehension::new(
l_sqbr, r_sqbr, layout, generators, guard,
)),
};
debug_exit_info!(self);
- Ok(arr)
+ Ok(lis)
}
/// Set, Dict, Record
diff --git a/crates/erg_parser/tests/invalid_collections.er b/crates/erg_parser/tests/invalid_collections.er
index d1963f199..554d4bcd3 100644
--- a/crates/erg_parser/tests/invalid_collections.er
+++ b/crates/erg_parser/tests/invalid_collections.er
@@ -1,4 +1,4 @@
-#[array]#
+#[list]#
[1,,]
[Nat;2;] # [Nat; 1]
a = [1: "a"] # [1: Nat]
@@ -37,4 +37,4 @@ t = (1, True, "a")
t.-1
r = {name = "John Doe"; age = 21; from="Unknown"}
-r.attr
\ No newline at end of file
+r.attr
diff --git a/crates/erg_parser/typespec.rs b/crates/erg_parser/typespec.rs
index 201d0cfc2..15bfc3aff 100644
--- a/crates/erg_parser/typespec.rs
+++ b/crates/erg_parser/typespec.rs
@@ -26,28 +26,28 @@ impl Parser {
"complex const accessor",
)),
},
- Expr::Array(array) => match array {
- Array::Normal(arr) => {
- let (elems, ..) = arr.elems.deconstruct();
+ Expr::List(list) => match list {
+ List::Normal(lis) => {
+ let (elems, ..) = lis.elems.deconstruct();
let mut const_elems = vec![];
for elem in elems.into_iter() {
let const_expr = Self::validate_const_expr(elem.expr)?;
const_elems.push(ConstPosArg::new(const_expr));
}
let elems = ConstArgs::pos_only(const_elems, None);
- let const_arr = ConstNormalArray::new(arr.l_sqbr, arr.r_sqbr, elems, None);
- Ok(ConstExpr::Array(ConstArray::Normal(const_arr)))
+ let const_lis = ConstNormalList::new(lis.l_sqbr, lis.r_sqbr, elems, None);
+ Ok(ConstExpr::List(ConstList::Normal(const_lis)))
}
- Array::WithLength(arr) => {
- let elem = Self::validate_const_expr(arr.elem.expr)?;
- let len = Self::validate_const_expr(*arr.len)?;
- let const_arr = ConstArrayWithLength::new(arr.l_sqbr, arr.r_sqbr, elem, len);
- Ok(ConstExpr::Array(ConstArray::WithLength(const_arr)))
+ List::WithLength(lis) => {
+ let elem = Self::validate_const_expr(lis.elem.expr)?;
+ let len = Self::validate_const_expr(*lis.len)?;
+ let const_lis = ConstListWithLength::new(lis.l_sqbr, lis.r_sqbr, elem, len);
+ Ok(ConstExpr::List(ConstList::WithLength(const_lis)))
}
other => Err(ParseError::feature_error(
line!() as usize,
other.loc(),
- "const array comprehension",
+ "const list comprehension",
)),
},
Expr::Set(set) => match set {
@@ -375,25 +375,25 @@ impl Parser {
))
}
- fn array_to_array_type_spec(array: Array) -> Result
+```
diff --git a/doc/EN/API/types/classes/Array!(T,N).md b/doc/EN/API/types/classes/List!(T,N).md
similarity index 96%
rename from doc/EN/API/types/classes/Array!(T,N).md
rename to doc/EN/API/types/classes/List!(T,N).md
index f8c80d5d3..a2aeebd08 100644
--- a/doc/EN/API/types/classes/Array!(T,N).md
+++ b/doc/EN/API/types/classes/List!(T,N).md
@@ -1,4 +1,4 @@
-# Array! T, N
+# List! T, N
Variable length array at compile time. `[t; n]` There is also a sugar cane syntax.
@@ -11,17 +11,14 @@ Variable length array at compile time. `[t; n]` There is also a sugar cane synta
* sample!(ref! self) -> T
* sample! ref! self, M: Nat -> [T; M]
-
Select a random element and return a copy.
* shuffle!(ref! self)
-
Shuffle contents.
* assert_len ref! self(_ ~> N, ...), N: Nat -> () or Panic
-
Verify length
Incorrect length will cause `panic`
diff --git a/doc/EN/API/types/classes/Array(T,N).md b/doc/EN/API/types/classes/List(T,N).md
similarity index 92%
rename from doc/EN/API/types/classes/Array(T,N).md
rename to doc/EN/API/types/classes/List(T,N).md
index 4d420be87..059878e15 100644
--- a/doc/EN/API/types/classes/Array(T,N).md
+++ b/doc/EN/API/types/classes/List(T,N).md
@@ -1,4 +1,4 @@
-# Array T: Type, N: Nat
+# List T: Type, N: Nat
`[T; N]` is syntactic sugar. `N` can be emitted (`[T; _]`).
@@ -23,7 +23,7 @@ assert ["a", "b", "c", "d", "e"].values_at([0, 1, 3]) == ["a", "b", "d"]
assert all(False for _in[])
```
-## methods of Array T, N | T <: Eq
+## methods of List T, N | T <: Eq
* freq self -> [{T: Nat}]
Returns the frequency of occurrence of an object.
diff --git a/doc/EN/API/types/traits/Container.md b/doc/EN/API/types/traits/Container.md
index 6b730ffaa..1b0a6e56b 100644
--- a/doc/EN/API/types/traits/Container.md
+++ b/doc/EN/API/types/traits/Container.md
@@ -10,7 +10,7 @@
## impl classes
-* `Array`
+* `List`
* `Tuple`
* `Str`
* `Range`
diff --git a/doc/EN/API/types/traits/Hashable.md b/doc/EN/API/types/traits/Hash.md
similarity index 77%
rename from doc/EN/API/types/traits/Hashable.md
rename to doc/EN/API/types/traits/Hash.md
index d1930f350..a74c8aa89 100644
--- a/doc/EN/API/types/traits/Hashable.md
+++ b/doc/EN/API/types/traits/Hash.md
@@ -1,4 +1,4 @@
-# Hashable
+# Hash
## required methods
diff --git a/doc/EN/API/types/traits/Sequence.md b/doc/EN/API/types/traits/Sequence.md
index e4a6b17d3..09f0699e2 100644
--- a/doc/EN/API/types/traits/Sequence.md
+++ b/doc/EN/API/types/traits/Sequence.md
@@ -16,7 +16,7 @@
## impl classes
-* `Array`
+* `List`
* `Tuple`
* `Str`
* `Range`
diff --git a/doc/EN/compiler/attribute_resolution.md b/doc/EN/compiler/attribute_resolution.md
index f84dcd8ec..57e000e7a 100644
--- a/doc/EN/compiler/attribute_resolution.md
+++ b/doc/EN/compiler/attribute_resolution.md
@@ -30,10 +30,10 @@ It succeeds only if the only type with `co_consts` in the namespace is `Code` (o
Erg closes function type checking within a module, so even if a type with `co_consts` is defined outside the module, passing an instance of it to the `consts` function will result in an error (to make this possible, you must use `Structural`, described below). This constraint allows the `consts` function to infer.
When a class attribute is defined, the type inferrer keeps track of the "attribute" and "defining class, attribute type" pairs.
-In the case of ``co_consts``, this pair is `{co_consts: {Code, Array(Obj, _)}}`.
+In the case of ``co_consts``, this pair is `{co_consts: {Code, List(Obj, _)}}`.
```erg
-method_to_classes: {co_consts: [{Code, Array(Obj, _)}], real: [{Int, Int}], times!: [{Nat, (self: Nat, proc!: () => NoneType) => NoneType}], ...}
+method_to_classes: {co_consts: [{Code, List(Obj, _)}], real: [{Int, Int}], times!: [{Nat, (self: Nat, proc!: () => NoneType) => NoneType}], ...}
```
Note that the value of the key-value pair is an array. Only if this array is of length 1, or has the smallest type element, the key is uniquely determined (otherwise a type error will occur).
@@ -41,11 +41,11 @@ Note that the value of the key-value pair is an array. Only if this array is of
Once the key is identified, the definition type is back-propagated to the type of ``?2``.
```erg
-?2(<: Code).co_consts: Array(Obj, _)
+?2(<: Code).co_consts: List(Obj, _)
```
-Finally, the type of `consts` is `Code -> Array(Obj, _)`.
+Finally, the type of `consts` is `Code -> List(Obj, _)`.
```erg
-consts(c: Code): Array(Obj, _) = c.co_consts
+consts(c: Code): List(Obj, _) = c.co_consts
```
diff --git a/doc/EN/compiler/hir.md b/doc/EN/compiler/hir.md
index 510ed2a5c..fd0300e1a 100644
--- a/doc/EN/compiler/hir.md
+++ b/doc/EN/compiler/hir.md
@@ -25,7 +25,7 @@ AST(Module[
body: Block[
Unary Op {
op: "!",
- expr: Array([]),
+ expr: List([]),
},
],
},
@@ -82,7 +82,7 @@ HIR(Module[
body: Block[
expr: UnaryOp{
op: "!",
- expr: Array([]),
+ expr: List([]),
t: [0..10, 0]!,
},
],
diff --git a/doc/EN/compiler/inference.md b/doc/EN/compiler/inference.md
index bc5045fc7..89b47dc11 100644
--- a/doc/EN/compiler/inference.md
+++ b/doc/EN/compiler/inference.md
@@ -50,19 +50,19 @@ The specific operations are as follows.
line 1. Def{sig: v, block: ![]}
get block type:
get UnaryOp type:
- getArray type: `['T; 0]`
+ getList type: `['T; 0]`
instantiate: `[?T; 0]`
(substitute, eval are omitted)
result: `Γ: {v: [?T; 0]!}`
expr returns `NoneType`: OK
line 2. CallMethod {obj: v, name: push!, args: [1]}
- get obj type: `Array!(?T, 0)`
- search: `Γ Array!(?T, 0).push!(Nat)`
- get: `Array!('T ~> 'T, 'N ~> 'N+1).push!: 'T => NoneType`
- instantiate: `Array!(?T, ?N).push!(?T) => NoneType`
- substitute(`S: {?T --> Nat, ?N --> 0}`): `Array!(Nat ~> Nat, 0 ~> 0+1).push!: Nat => NoneType`
- eval: `Array!(Nat, 0 ~> 1).push!: Nat => NoneType`
+ get obj type: `List!(?T, 0)`
+ search: `Γ List!(?T, 0).push!(Nat)`
+ get: `List!('T ~> 'T, 'N ~> 'N+1).push!: 'T => NoneType`
+ instantiate: `List!(?T, ?N).push!(?T) => NoneType`
+ substitute(`S: {?T --> Nat, ?N --> 0}`): `List!(Nat ~> Nat, 0 ~> 0+1).push!: Nat => NoneType`
+ eval: `List!(Nat, 0 ~> 1).push!: Nat => NoneType`
result: `Γ: {v: [Nat; 1]!}`
expr returns `NoneType`: OK
diff --git a/doc/EN/compiler/parsing.md b/doc/EN/compiler/parsing.md
index fbc7fc767..3c18d2ed3 100644
--- a/doc/EN/compiler/parsing.md
+++ b/doc/EN/compiler/parsing.md
@@ -21,8 +21,8 @@ In fact, there is (very confusingly) a right-sided value on the left side of `=`
There can even be a left-side value within a right-side value.
```python
-# i is the left-hand side value, Array(Int) and [1, 2, 3] are the right-hand side values
-i: Array(Int) = [1, 2, 3]
+# i is the left-hand side value, List(Int) and [1, 2, 3] are the right-hand side values
+i: List(Int) = [1, 2, 3]
# `[1, 2, 3].iter().map i -> i + 1` is the right-hand side value, but i to the left of -> is the left-hand side value
a = [1, 2, 3].iter().map i -> i + 1
# {x = 1; y = 2} is the right side value, but x, y are the left side values
diff --git a/doc/EN/faq_technical.md b/doc/EN/faq_technical.md
index 6a3b17de2..af66a4b28 100644
--- a/doc/EN/faq_technical.md
+++ b/doc/EN/faq_technical.md
@@ -35,10 +35,10 @@ Also, input that is valid according to the specification but deemed undesirable
## Why doesn't Tuple have a constructor (`__call__`)?
Erg tuples must have a compile-time length. Therefore, a tuple is constructed almost only by a tuple literal.
-If the length is not known until runtime, an immutable array (`Array`) can be used instead.
+If the length is not known until runtime, an immutable array (`List`) can be used instead.
```erg
-arr = Array map(int, input!().split " ")
+arr = List map(int, input!().split " ")
```
## I got runtime errors in Erg that I did not get in Python. What could be the cause?
diff --git a/doc/EN/syntax/01_literal.md b/doc/EN/syntax/01_literal.md
index 5e8630d06..99a607130 100644
--- a/doc/EN/syntax/01_literal.md
+++ b/doc/EN/syntax/01_literal.md
@@ -70,7 +70,7 @@ assert 1e-10 == 0.0000000001
Each of these literals has its own documentation describing them separately, so please refer to that documentation for details.
-### [Array Literal](./10_array.md)
+### [List Literal](./10_list.md)
```python
[], [1], [1, 2, 3], ["1", "2",], ...
@@ -100,7 +100,7 @@ Each of these literals has its own documentation describing them separately, so
{}, {1}, {1, 2, 3}, {"1", "2", "1"}, ...
```
-As a difference from `Array` literals, duplicate elements are removed in `Set`.
+As a difference from `List` literals, duplicate elements are removed in `Set`.
```python
assert {1, 2, 1} == {1, 2}
diff --git a/doc/EN/syntax/02_name.md b/doc/EN/syntax/02_name.md
index 0ae5650fb..b5209458b 100644
--- a/doc/EN/syntax/02_name.md
+++ b/doc/EN/syntax/02_name.md
@@ -29,7 +29,7 @@ l1 = l2 = [1, 2, 3] # SyntaxError: multiple assignment not allowed
```python
# OK
l1 = [1, 2, 3]
-l2 = l1.clone()
+l2 = l1
```
It is also not possible to reassign to a variable. The syntax that can be used instead, to hold mutable states, are described later.
diff --git a/doc/EN/syntax/07_side_effect.md b/doc/EN/syntax/07_side_effect.md
index ed3d77c0c..9fe5c8abc 100644
--- a/doc/EN/syntax/07_side_effect.md
+++ b/doc/EN/syntax/07_side_effect.md
@@ -28,7 +28,7 @@ C!.
x
```
-Procedural methods can also take [ownership](./19_ownership.md) of `self`. Remove `ref` or `ref!` from the method definition.
+Procedural methods can also take [ownership](./20_ownership.md) of `self`. Remove `ref` or `ref!` from the method definition.
```python,compile_fail
n = 1
diff --git a/doc/EN/syntax/09_builtin_procs.md b/doc/EN/syntax/09_builtin_procs.md
index eff9af732..dc0e4a31b 100644
--- a/doc/EN/syntax/09_builtin_procs.md
+++ b/doc/EN/syntax/09_builtin_procs.md
@@ -10,5 +10,5 @@ Although in pure Erg semantics no difference can be found between objects with t
```
diff --git a/doc/EN/syntax/SUMMARY.md b/doc/EN/syntax/SUMMARY.md index d724eb91a..917b68d0f 100644 --- a/doc/EN/syntax/SUMMARY.md +++ b/doc/EN/syntax/SUMMARY.md @@ -15,7 +15,7 @@ This file is for generating The Erg Book. Do not add badges, etc. - [Side effects and procedures](./07_side_effect.md) - [Procedures](./08_procedure.md) - [Built-in procedure](./09_builtin_procs.md) -- [Array](./10_array.md) +- [List](./10_list.md) - [Dict](./11_dict.md) - [Subscript (index access)](./12_container_ownership.md) - [Tuple](./13_tuple.md) diff --git a/doc/EN/syntax/indexes.md b/doc/EN/syntax/indexes.md index 70e88b923..31e541641 100644 --- a/doc/EN/syntax/indexes.md +++ b/doc/EN/syntax/indexes.md @@ -8,17 +8,17 @@ Also, see [here](../terms.md) for terminology. * ! → [side effect](./07_side_effect.md) * !-type → [mutable type](./type/18_mut.md) -* ? → [error handling](./31_error_handling.md) -* # → [Str](./00_basic.md/#comments) +* ? → [error handling](./32_error_handling.md) +* # → [Str](./00_basic.md#comments) * $ → [shared](./type/advanced/shared.md) * % * & * && -* [′ (single quote)](./21_naming_rule.md#literal-identifiers) +* [′ (single quote)](./22_naming_rule.md#literal-identifiers) * [" (double quote)](./01_literal.md#str-literal) * () → [Tuple](./13_tuple.md) * * - * * → [*-less multiplication](./01_literal.md/#less-multiplication) + * * → [*-less multiplication](./01_literal.md#less-multiplication) * + (prefix) → [operator](./06_operator.md) * +_ → + (prefix) * + (infix) → [operator](./06_operator.md) @@ -28,42 +28,42 @@ Also, see [here](../terms.md) for terminology. * −_ → − (prefix) * − (infix) → [operator](./06_operator.md) * − (infix) → [Trait](./type/03_trait.md) - * −> → [anonymous function](./22_lambda.md) -* . → [Visibility](./20_visibility.md) - * .. → [closed range operator](./01_literal.md/#range-object) - * ..< → [right-open range operator](./01_literal.md/#range-object) + * −> → [anonymous function](./23_lambda.md) +* . → [Visibility](./21_visibility.md) + * .. → [closed range operator](./01_literal.md#range-object) + * ..< → [right-open range operator](./01_literal.md#range-object) * ... - * ... → [Extract assignment](./29_spread_syntax.md#extract-assignment) + * ... → [Extract assignment](./30_spread_syntax.md#extract-assignment) * ... → [Variable-length arguments](./04_function.md#variable-length-arguments) * / * : * : → [Colon application style](./04_function.md) * : → [Type ascription](./03_declaration.md) * : → [Keyword arguments](./04_function.md) - * :: → [private variable modifier](./20_visibility.md) + * :: → [private variable modifier](./21_visibility.md) * := → [default parameters](./04_function.md) * ; * < * <: → [Subtype specification](./type/02_basic.md) * << * <= - * <.. → [left-open range operator](./01_literal.md/#range-object) - * <..< → [open range operator](./01_literal.md/#range-object) -* = → [Variable](./20_visibility.md) + * <.. → [left-open range operator](./01_literal.md#range-object) + * <..< → [open range operator](./01_literal.md#range-object) +* = → [Variable](./21_visibility.md) * == * => → [anonymous procedure operator](./08_procedure.md) * > * >> * >= -* @ → [decorator](./30_decorator.md) -* [] → [Array](./10_array.md) +* @ → [decorator](./31_decorator.md) +* [] → [List](./10_list.md) * \ → [Escaping](./00_basic.md) * ^ * ^^ * _ → [Type erasure](./type/advanced/erasure.md) * _+_ → + (infix) * _-_ → − (infix) -* [`` (back quote)](./23_subroutine.md#operator) +* [`` (back quote)](./24_subroutine.md#operator) * {} * [{} type](./type/01_type_system.md) * {=} → [Type System](./type/01_type_system.md#classification) @@ -83,11 +83,11 @@ Also, see [here](../terms.md) for terminology. * [algebraic type](./type/13_algebraic.md) * [And] * [and] -* [anonymous function](./22_lambda.md) +* [anonymous function](./23_lambda.md) * anonymous type → [Type system](./type/01_type_system.md) -* [Array](./10_array.md) +* [List](./10_list.md) * assert -* [Attach](./30_decorator.md#attach) +* [Attach](./31_decorator.md#attach) * [attribute](type/09_attributive.md) * [Attribute definitions](./type/02_basic.md#attribute-definitions) * [Attribute type](./type/09_attributive.md) @@ -96,7 +96,7 @@ Also, see [here](../terms.md) for terminology. * [Bool, Boolean](./01_literal.md#boolean-object) * [Boolean object](./01_literal.md#boolean-object) -* [borrowing](./19_ownership.md#borrow) +* [borrowing](./20_ownership.md#borrow) ### C @@ -104,24 +104,24 @@ Also, see [here](../terms.md) for terminology. * [Comments](./00_basic.md#comments) * [Complex object](./01_literal.md#complex-object) * [Compile-time functions](./04_function.md#compile-time-functions) -* [circular references](./19_ownership.md#circular-references) +* [circular references](./20_ownership.md#circular-references) * [Class](./type/04_class.md) * [Class relationship](./type/04_class.md#class-relationships) * [Class upcasting](./type/16_subtyping.md#class-upcasting) * [Colon application style](./04_function.md#colon-application-style) -* [Closure](./24_closure.md) +* [Closure](./25_closure.md) * [Compound literals](./01_literal.md#compound-literals) * [Complement](./type/13_algebraic.md#complement) -* [Comprehension](./28_comprehension.md) -* [constant](./18_mutability.md#constant) +* [Comprehension](./29_comprehension.md) +* [constant](./19_mutability.md#constant) * [Constants](./02_name.md#constants) -* [Context](./31_error_handling.md#context) +* [Context](./32_error_handling.md#context) ### D * [Data type](./type/01_type_system.md#data-type) * [Declaration](./03_declaration.md) -* [decorator](./30_decorator.md) +* [decorator](./31_decorator.md) * [Default parameters](./04_function.md#default-parameters) * [Del](./02_name.md#delete-an-variable) * [Dependent type](./type/14_dependent.md) @@ -137,10 +137,10 @@ Also, see [here](../terms.md) for terminology. * [Enum class](./type/04_class.md#enum-class) * [Enum type](./type/11_enum.md) * [Enumerated, Interval and Refinement types](./type/12_refinement.md#enumerated-interval-and-refinement-types) -* [error handling](./31_error_handling.md) +* [error handling](./32_error_handling.md) * [Existential type](./type/advanced/existential.md) * [Exponential literal](./01_literal.md#exponential-literal) -* [Extract assignment](./29_spread_syntax.md#extract-assignment) +* [Extract assignment](./30_spread_syntax.md#extract-assignment) ### F @@ -148,14 +148,14 @@ Also, see [here](../terms.md) for terminology. * [Float object](./01_literal.md#float-object) * [for](./05_builtin_funcs.md#for) * [For-All patch](./type/07_patch.md#for-all-patch) -* [freeze](./19_ownership.md#freeze) +* [freeze](./20_ownership.md#freeze) * [Function](./04_function.md) * [Function definition with multiple patterns](./04_function.md#function-definition-with-multiple-patterns) ### G * [GADTs(Generalized Algebraic Data Types)](./type/advanced/GADTs.md) -* [Generator](./35_generator.md) +* [Generator](./36_generator.md) * [Glue Patch](./type/07_patch.md#glue-patch) ### H @@ -166,19 +166,19 @@ Also, see [here](../terms.md) for terminology. * [id](./09_builtin_procs.md#id) * [if](./05_builtin_funcs.md#if) -* [import](./34_package_system.md) -* [impl](./30_decorator.md#impl) +* [import](./35_package_system.md) +* [impl](./31_decorator.md#impl) * in * [Indention](./00_basic.md#indentation) * [Instant block](./14_record.md#instant-block) * [Instance/class attributes](./type/04_class.md#instance-and-class-attributes) -* [inheritable](./30_decorator.md#inheritable) +* [inheritable](./31_decorator.md#inheritable) * [inheritance](./type/05_inheritance.md) * [Int](./01_literal.md) -* [Integration with Python](./33_integration_with_Python.md) +* [Integration with Python](./34_integration_with_Python.md) * [Interval Type](./type/10_interval.md) * [Intersection](./type/13_algebraic.md#intersection) -* [Iterator](./17_iterator.md) +* [Iterator](./18_iterator.md) ### J @@ -189,22 +189,22 @@ Also, see [here](../terms.md) for terminology. ### L -* lambda → [anonymous function](./22_lambda.md) +* lambda → [anonymous function](./23_lambda.md) * let-polymorphism → [rank 1 polymorphism] -* [Literal Identifiers](./21_naming_rule.md#literal-identifiers) +* [Literal Identifiers](./22_naming_rule.md#literal-identifiers) ### M * match * [Marker trait](./type/advanced/marker_trait.md) * [Method](./07_side_effect.md#methods) -* Modifier → [decorator](./30_decorator.md) -* [module](./25_module.md) +* Modifier → [decorator](./31_decorator.md) +* [module](./26_module.md) * [Multiple inheritance](type/05_inheritance.md#multiple-inheritance) * [Multi-layer (multi-level) Inheritance](type/05_inheritance.md#multi-layer-multi-level-inheritance) * [Mutable type](./type/18_mut.md) * [Mutable structure type](./type/advanced/mut_struct.md) -* [Mutability](./18_mutability.md) +* [Mutability](./19_mutability.md) ### N @@ -220,28 +220,28 @@ Also, see [here](../terms.md) for terminology. ### O -* [Object](./26_object_system.md) +* [Object](./27_object_system.md) * [Option] * [Or] * [or] * [Ord] -* [ownership system](./19_ownership.md) +* [ownership system](./20_ownership.md) * [Overloading](./type/advanced/overloading.md) * [Overriding](./type/05_inheritance.md#overriding) * [Override in trait](./type/03_trait.md#override-in-trait) ### P -* [Panic](./31_error_handling.md#panic) +* [Panic](./32_error_handling.md#panic) * [Patch](./type/07_patch.md) -* [Pattern match](./27_pattern_matching.md) +* [Pattern match](./28_pattern_matching.md) * [Phantom class](./type/advanced/phantom.md) -* [pipeline operator](./32_pipeline.md) +* [pipeline operator](./33_pipeline.md) * [Predicate](./type/19_bound.md#predicate) * print! * [Procedures](./08_procedure.md) * [Projection type](./type/advanced/projection.md) -* Python → [Integration with Python](./33_integration_with_Python.md) +* Python → [Integration with Python](./34_integration_with_Python.md) ### Q @@ -257,9 +257,9 @@ Also, see [here](../terms.md) for terminology. * [Recursive functions](./04_function.md#recursive-functions) * [Refinement pattern](./type/12_refinement.md#refinement-pattern) * [Refinement type](./type/12_refinement.md) -* [replication](./19_ownership.md#replication) +* [replication](./20_ownership.md#replication) * [Replacing traits](./type/05_inheritance.md#replacing-traits-or-what-looks-like-it) -* Result → [error handling](./31_error_handling.md) +* Result → [error handling](./32_error_handling.md) ### S @@ -269,9 +269,9 @@ Also, see [here](../terms.md) for terminology. * [Shared reference](./type/advanced/shared.md) * [side-effect](./07_side_effect.md) * [Smart cast](./type/12_refinement.md#smart-cast) -* [Spread assignment](./29_spread_syntax.md) +* [Spread assignment](./30_spread_syntax.md) * [special type variables](./type/advanced/special.md#special-type-variables) -* [Stack trace](./31_error_handling.md#stack-trace) +* [Stack trace](./32_error_handling.md#stack-trace) * [Structure type](./type/01_type_system.md#structure-type-anonymous-type) * [Structural patch](./type/07_patch.md#structural-patch) * [Structural trait](./type/03_trait.md#structural-traits) @@ -282,11 +282,11 @@ Also, see [here](../terms.md) for terminology. * [Subtyping of subroutines](./type/16_subtyping.md#subtyping-of-subroutines) * [Subtype specification](./type/02_basic.md#subtype-specification) * [Subtyping of polymorphic function types](./type/15_quantified.md#subtyping-of-polymorphic-function-types) -* [Subroutine signatures](./23_subroutine.md) +* [Subroutine signatures](./24_subroutine.md) ### T -* [Test](./30_decorator.md#test) +* [Test](./31_decorator.md#test) * [Traits](./type/03_trait.md) * [Trait inclusion](./type/03_trait.md#trait-inclusion) * True → [Boolean object](./01_literal.md#boolean-object) diff --git a/doc/EN/syntax/quick_tour.md b/doc/EN/syntax/quick_tour.md index 10c425cf5..7fe880726 100644 --- a/doc/EN/syntax/quick_tour.md +++ b/doc/EN/syntax/quick_tour.md @@ -222,7 +222,7 @@ right(_, r) = r ### Variable length patterns -Used in combination with the tuple/array/record pattern described later. +Used in combination with the tuple/list/record pattern described later. ```python [i, *j] = [1, 2, 3, 4] @@ -240,7 +240,7 @@ assert first(1, 2, 3) == 1 m, n = 1, 2 ``` -### Array pattern +### List pattern ```python length [] = 0 diff --git a/doc/EN/syntax/type/01_type_system.md b/doc/EN/syntax/type/01_type_system.md index eddcde0be..4b5e5af4d 100644 --- a/doc/EN/syntax/type/01_type_system.md +++ b/doc/EN/syntax/type/01_type_system.md @@ -45,14 +45,14 @@ In Erg, the nominal types are classes and traits. When we simply say class/trait The type for the entire nominal type (`NominalType`) and the type for the entire structural type (`StructuralType`) are subtypes of the type for the entire type (`Type`). -Erg can pass arguments (type arguments) to the type definition. An `Option`, `Array`, etc. with type arguments are called a polynomial kind. These are not themselves types, but they become types by applying arguments. Types such as `Int`, `Str`, etc., which have no arguments, are called simple types (scalar types). +Erg can pass arguments (type arguments) to the type definition. An `Option`, `List`, etc. with type arguments are called a polynomial kind. These are not themselves types, but they become types by applying arguments. Types such as `Int`, `Str`, etc., which have no arguments, are called simple types (scalar types). A type can be regarded as a set, and there is an inclusion relation. For example, `Num` contains `Add`, `Sub`, etc., and `Int` contains `Nat`. The upper class of all classes is `Object == Class {:}` and the lower class of all types is `Never == Class {}`. This is described below. ## Types -A type like `Array T` can be regarded as a function of type `Type -> Type` that takes type `T` as an argument and returns type `Array T` (also called Kind in type theory). Types like `Array T` are specifically called polymorphic types, and `Array` itself is called unary Kind. +A type like `List T` can be regarded as a function of type `Type -> Type` that takes type `T` as an argument and returns type `List T` (also called Kind in type theory). Types like `List T` are specifically called polymorphic types, and `List` itself is called unary Kind. The type of a function whose argument and return types are known is denoted as `(T, U) -> V`. If you want to specify an entire two-argument function of the same type, you can use `|T| (T, T) -> T`, and if you want to specify an entire N-argument function, you can use `Func N`. However, the `Func N` type has no information about the number of arguments or their types, so all return values are of type `Obj` when called. @@ -60,7 +60,7 @@ The `Proc` type is denoted as `() => Int` and so on. Also, the name of the `Proc A `Method` type is a function/procedure whose first argument is the object `self` to which it belongs (by reference). For dependent types, you can also specify the type of yourself after the method is applied. This is `T!(!N)` type and `T!(N ~> N-1). () => Int` and so on. -Erg's array (Array) is what Python calls a list. `[Int; 3]` is an array class that contains three objects of type `Int`. +Erg's array (List) is what Python calls a list. `[Int; 3]` is an array class that contains three objects of type `Int`. > __Note__: `(Type; N)` is both a type and a value, so it can be used like this. > @@ -113,7 +113,7 @@ Since types are also objects, there are attributes on the types themselves. Such As mentioned earlier, a "type" in Erg roughly means a set of objects. The following is a definition of the `Add` type, which requires `+` (the middle operator). `R, O` are the so-called type parameters, which can be a true type (class) such as `Int` or `Str`. In other languages, type parameters are given a special notation (generics, templates, etc.), but in Erg they can be defined just like normal parameters. -Type parameters can also be used for types other than type objects. For example, the array type `[Int; 3]` is a syntax sugar for `Array Int, 3`. If the type implementations overlap, the user must explicitly choose one. +Type parameters can also be used for types other than type objects. For example, the array type `[Int; 3]` is a syntax sugar for `List Int, 3`. If the type implementations overlap, the user must explicitly choose one. ```python Add R = Trait { diff --git a/doc/EN/syntax/type/02_basic.md b/doc/EN/syntax/type/02_basic.md index 22bf97ef7..ec770d5ad 100644 --- a/doc/EN/syntax/type/02_basic.md +++ b/doc/EN/syntax/type/02_basic.md @@ -15,11 +15,11 @@ Type specifications are more useful when defining subroutines and types. ```python # Type specification for parameters -f x, y: Array Int = ... -T X, Y: Array Int = ... +f x, y: List Int = ... +T X, Y: List Int = ... ``` -Note that in the above case, `x, y` are both `Array Int`. +Note that in the above case, `x, y` are both `List Int`. ```python # The value of a capital variable must be a constant expression @@ -137,7 +137,7 @@ Types can be aliased. This allows long types, such as record types, to be shorte Id = Int Point3D = {x = Int; y = Int; z = Int} IorS = Int or Str -Vector = Array Int +Vector = List Int ``` Also, when displaying errors, the compiler will use aliases for composite types (in the above example, right-hand-side types other than the first) if they are defined. @@ -150,8 +150,8 @@ The purpose is also to prevent adding aliases on top of types that already have Id = Int UserId = Int # TypeWarning: duplicate aliases: Id and UserId -Ids = Array Id -Ints = Array Int # TypeWarning: duplicate aliases: Isd and Ints +Ids = List Id +Ints = List Int # TypeWarning: duplicate aliases: Isd and Ints IorS = Int or Str IorSorB = IorS or Bool diff --git a/doc/EN/syntax/type/03_trait.md b/doc/EN/syntax/type/03_trait.md index 85a38ea85..1991f3a4c 100644 --- a/doc/EN/syntax/type/03_trait.md +++ b/doc/EN/syntax/type/03_trait.md @@ -77,7 +77,7 @@ Trait is also a type, so it can be used for normal type specification. ```python points: [Norm; 2] = [Point2D::new(1, 2), Point2D::new(3, 4)] -assert points.iter().map(x -> x.norm()).collect(Array) == [5, 25]. +assert points.iter().map(x -> x.norm()).collect(List) == [5, 25]. ``` ## Trait inclusion @@ -151,11 +151,11 @@ Mapper T: Type = Trait { .map = (self: Self, T -> U) -> Self.MapIter U } -# ArrayIterator <: Mapper -# ArrayIterator.MapIter == ArrayMapper -# [1, 2, 3].iter(): ArrayIterator Int -# [1, 2, 3].iter().map(x -> "\{x}"): ArrayMapper Str -assert [1, 2, 3].iter().map(x -> "\{x}").collect(Array) == ["1", "2", "3"]. +# ListIterator <: Mapper +# ListIterator.MapIter == ListMapper +# [1, 2, 3].iter(): ListIterator Int +# [1, 2, 3].iter().map(x -> "\{x}"): ListMapper Str +assert [1, 2, 3].iter().map(x -> "\{x}").collect(List) == ["1", "2", "3"]. ``` ## Override in Trait diff --git a/doc/EN/syntax/type/08_value.md b/doc/EN/syntax/type/08_value.md index c687c6848..21bb5b18b 100644 --- a/doc/EN/syntax/type/08_value.md +++ b/doc/EN/syntax/type/08_value.md @@ -12,7 +12,7 @@ Value = ( or Bool or Str or NoneType - or Array Const + or List Const or Tuple Const or Set Const or ConstFunc(Const, _) diff --git a/doc/EN/syntax/type/12_refinement.md b/doc/EN/syntax/type/12_refinement.md index 92905d257..5bfb6c8c6 100644 --- a/doc/EN/syntax/type/12_refinement.md +++ b/doc/EN/syntax/type/12_refinement.md @@ -10,8 +10,8 @@ Nat = 0.. _ Odd = {N: Int | N % 2 == 1} Char = StrWithLen 1 # StrWithLen 1 == {_: StrWithLen N | N == 1} -[Int; 3] == {_: Array Int, N | N == 3} -Array3OrMore == {A: Array _, N | N >= 3} +[Int; 3] == {_: List Int, N | N == 3} +List3OrMore == {A: List _, N | N >= 3} ``` When there are multiple preds, they can be separated by `;` or `and` or `or`. `;` and `and` mean the same thing. @@ -83,7 +83,7 @@ Just as `_: {X}` can be rewritten as `X` (constant pattern), `_: {X: T | Pred}` ```python # method `.m` is defined for arrays of length 3 or greater -Array(T, N | N >= 3) +List(T, N | N >= 3) .m(&self) = ... ``` diff --git a/doc/EN/syntax/type/14_dependent.md b/doc/EN/syntax/type/14_dependent.md index fdcbc209c..e598a6e58 100644 --- a/doc/EN/syntax/type/14_dependent.md +++ b/doc/EN/syntax/type/14_dependent.md @@ -3,7 +3,7 @@ Dependent types are a feature that can be said to be the biggest feature of Erg. A dependent type is a type that takes a value as an argument. Ordinary polymorphic types can take only types as arguments, but dependent types relax that restriction. -Dependent types are equivalent to `[T; N]` (`Array(T, N)`). +Dependent types are equivalent to `[T; N]` (`List(T, N)`). This type is determined not only by the content type `T` but also by the number of contents `N`. `N` contains an object of type `Nat`. ```python @@ -67,7 +67,7 @@ vm.stop!() # TypeError: VM!(!"stopped", 1) doesn't have .stop!() You can also embed or inherit existing types to create dependent types. ```python -MyArray(T, N) = Inherit[T; N] +MyList(T, N) = Inherit[T; N] # The type of self: Self(T, N) changes in conjunction with .array MyStruct!(T, N: Nat!) = Class {.array: [T; !N]} @@ -75,4 +75,4 @@ MyStruct!(T, N: Nat!) = Class {.array: [T; !N]}
\ No newline at end of file + diff --git a/doc/EN/syntax/type/15_quantified.md b/doc/EN/syntax/type/15_quantified.md index 3854feec7..6d45aaaa2 100644 --- a/doc/EN/syntax/type/15_quantified.md +++ b/doc/EN/syntax/type/15_quantified.md @@ -99,7 +99,7 @@ Iterator T = Trait { } it = [1, 2, 3].iter().map i -> i + 1 -it.collect(Array) # [2, 3, 4]. +it.collect(List) # [2, 3, 4]. ``` Type variables can only be declared during `||`. However, once declared, they can be used anywhere until they exit scope. diff --git a/doc/EN/syntax/type/18_mut.md b/doc/EN/syntax/type/18_mut.md index 016b084e8..ad7e107f4 100644 --- a/doc/EN/syntax/type/18_mut.md +++ b/doc/EN/syntax/type/18_mut.md @@ -37,7 +37,7 @@ The `.freeze_map` method operates on values unchanged. ```python a = [1, 2, 3].into [Nat; !3] -x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(Array) +x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(List) ``` In a polymorphic immutable type the type argument `T` of the type is implicitly assumed to be immutable. diff --git a/doc/EN/syntax/type/20_compound.md b/doc/EN/syntax/type/20_compound.md index db871b9a3..8d49f61e6 100644 --- a/doc/EN/syntax/type/20_compound.md +++ b/doc/EN/syntax/type/20_compound.md @@ -24,7 +24,7 @@ However, these rules do not apply to the tuple-like part of a Function type, bec In addition, return values of Unit types can be ignored, but return values of other tuple types cannot be ignored. -## Array Type +## List Type ```erg [], [X; 0], [X; 1], [X; 2], ..., [X; _] == [X] @@ -37,7 +37,7 @@ The same subtype rules exist for arrays as for tuples. * forall N in 0..- Previous | Next + Previous | Next
diff --git a/doc/JA/syntax/10_array.md b/doc/JA/syntax/10_list.md similarity index 64% rename from doc/JA/syntax/10_array.md rename to doc/JA/syntax/10_list.md index 7d7cc2b9e..2f0a8e6a5 100644 --- a/doc/JA/syntax/10_array.md +++ b/doc/JA/syntax/10_list.md @@ -1,8 +1,8 @@ -# 配列 +# リスト -[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/10_array.md%26commit_hash%3D603abbd5fa3f8baffe0d614758e1a554705e6732)](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/10_array.md&commit_hash=603abbd5fa3f8baffe0d614758e1a554705e6732) +[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/10_list.md%26commit_hash%3D603abbd5fa3f8baffe0d614758e1a554705e6732)](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/10_list.md&commit_hash=603abbd5fa3f8baffe0d614758e1a554705e6732) -配列はもっとも基本的な __コレクション(集約)__ です。 +リストはもっとも基本的な __コレクション(集約)__ です。 コレクションとは、内部にオブジェクトを複数保持できるオブジェクトのことです。 ```python @@ -16,7 +16,7 @@ mut_a[0].inc!() assert mut_a == [2, 2, 3] ``` -配列には、原則として違う型のオブジェクトを入れることはできません。 +リストには、原則として違う型のオブジェクトを入れることはできません。 ```python,compile_fail [1, "a"] # TypeError: 1st element is Int, but 2nd element is Str @@ -36,7 +36,7 @@ assert mut_a == [2, 2, 3] ## スライス -配列は、複数の値をまとめて取り出すこともできます。これをスライスと呼びます。 +リストは、複数の値をまとめて取り出すこともできます。これをスライスと呼びます。 ```python l = [1, 2, 3, 4] @@ -49,7 +49,7 @@ assert l[1..1] == [2] assert l[..].step(2) == [2, 4] ``` -スライスで得られるオブジェクトは配列の(不変)参照です。 +スライスで得られるオブジェクトはリストの(不変)参照です。 ```python print! Typeof l[1..2] # Ref [Int; 4] diff --git a/doc/JA/syntax/11_dict.md b/doc/JA/syntax/11_dict.md index 6ede7750d..8c37310fd 100644 --- a/doc/JA/syntax/11_dict.md +++ b/doc/JA/syntax/11_dict.md @@ -36,7 +36,7 @@ x = f(...) # x == 2 {2x+2: 1, 2(x+1): 2} # {6: 2} ``` -空のDictは`{:}`で生成します。`{}`は空の配列を表すことに注意してください。 +空のDictは`{:}`で生成します。`{}`は空の集合を表すことに注意してください。 ```python mut_dict = !{:} diff --git a/doc/JA/syntax/13_tuple.md b/doc/JA/syntax/13_tuple.md index 104b30f36..d083f20b1 100644 --- a/doc/JA/syntax/13_tuple.md +++ b/doc/JA/syntax/13_tuple.md @@ -2,8 +2,8 @@ [![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/13_tuple.md%26commit_hash%3De959b3e54bfa8cee4929743b0193a129e7525c61)](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/13_tuple.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) -タプルは配列と似ていますが、違う型のオブジェクトを保持できます。 -このようなコレクションを非等質なコレクションと呼びます。対して等質なコレクションには配列、セットなどがあります。 +タプルはリストと似ていますが、違う型のオブジェクトを保持できます。 +このようなコレクションを非等質なコレクションと呼びます。対して等質なコレクションにはリスト、セットなどがあります。 ```python t = (1, True, "a") @@ -12,7 +12,7 @@ assert(i == 1 and b == True and s == "a") ``` タプル`t`は`t.n`の形式でn番目の要素を取り出すことができます。Pythonと違い、`t[n]`ではないことに注意してください。 -これは、タプル要素のアクセスはメソッド(配列の`[]`はメソッドです)というより属性に近い(コンパイル時に要素の存在がチェックされる、nによって型が変わりうる)ためです。 +これは、タプル要素のアクセスはメソッド(リストの`[]`はメソッドです)というより属性に近い(コンパイル時に要素の存在がチェックされる、nによって型が変わりうる)ためです。 ```python assert t.0 == 1 @@ -27,7 +27,7 @@ t = 1, True, "a" i, b, s = t ``` -タプルは違う型のオブジェクトを保持できますが、そのかわり配列のようなイテレーションができなくなります。 +タプルは違う型のオブジェクトを保持できますが、そのかわりリストのようなイテレーションができなくなります。 ```python,compile_fail t: ({1}, {2}, {3}) = (1, 2, 3) @@ -35,12 +35,12 @@ t: ({1}, {2}, {3}) = (1, 2, 3) ``` ```python -# すべて同じ型の場合配列と同じように`(T; n)`で表せるが、これでもイテレーションは出来ない +# すべて同じ型の場合リストと同じように`(T; n)`で表せるが、これでもイテレーションは出来ない t: (Int; 3) = (1, 2, 3) assert (Int; 3) == (Int, Int, Int) ``` -ただし、非等質なコレクション(タプルなど)はアップキャスト、Intersectionなどによって等質なコレクション(配列など)に変換できます。 +ただし、非等質なコレクション(タプルなど)はアップキャスト、Intersectionなどによって等質なコレクション(リストなど)に変換できます。 これを等質化といいます。 ```python diff --git a/doc/JA/syntax/15_set.md b/doc/JA/syntax/15_set.md index ccfbed699..5e61cd5a9 100644 --- a/doc/JA/syntax/15_set.md +++ b/doc/JA/syntax/15_set.md @@ -2,7 +2,7 @@ [![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/15_set.md%26commit_hash%3De959b3e54bfa8cee4929743b0193a129e7525c61)](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/15_set.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) -セットは集合を表し、データ構造的には重複、順序のない配列です。 +セットは集合を表し、データ構造的には重複、順序のないリストです。 ```python assert Set.from([1, 2, 3, 2, 1]) == {1, 2, 3} diff --git a/doc/JA/syntax/18_iterator.md b/doc/JA/syntax/18_iterator.md index 414375610..09df33944 100644 --- a/doc/JA/syntax/18_iterator.md +++ b/doc/JA/syntax/18_iterator.md @@ -34,22 +34,22 @@ Iterable T = Trait { ```python assert [1, 2, 3] in Iterable(Int) assert 1..3 in Iterable(Int) -assert [1, 2, 3].Iterator == ArrayIterator +assert [1, 2, 3].Iterator == ListIterator assert (1..3).Iterator == RangeIterator -log [1, 2, 3].iter() #diff --git a/doc/JA/syntax/34_integration_with_Python.md b/doc/JA/syntax/34_integration_with_Python.md index 5be1710e9..34df65c91 100644 --- a/doc/JA/syntax/34_integration_with_Python.md +++ b/doc/JA/syntax/34_integration_with_Python.md @@ -102,14 +102,14 @@ f: (Int -> Str) and (Int -> Int) ## トレイト実装宣言 -クラスに対してトレイトの実装とトレイトメンバーの宣言を行う場合、以下のように記述します([numpy.NDArrayの型宣言](https://github.com/erg-lang/erg/blob/main/crates/erg_compiler/lib/external/numpy.d/__init__.d.er)より抜粋)。 +クラスに対してトレイトの実装とトレイトメンバーの宣言を行う場合、以下のように記述します([numpy.NDListの型宣言](https://github.com/erg-lang/erg/blob/main/crates/erg_compiler/lib/external/numpy.d/__init__.d.er)より抜粋)。 ```erg -.NDArray = 'ndarray': (T: Type, Shape: [Nat; _]) -> ClassType +.NDList = 'ndarray': (T: Type, Shape: [Nat; _]) -> ClassType ... -.NDArray(T, S)|<: Add .NDArray(T, S)|. - Output: {.NDArray(T, S)} - __add__: (self: .NDArray(T, S), other: .NDArray(T, S)) -> .NDArray(T, S) +.NDList(T, S)|<: Add .NDList(T, S)|. + Output: {.NDList(T, S)} + __add__: (self: .NDList(T, S), other: .NDList(T, S)) -> .NDList(T, S) ``` ## 注意点 diff --git a/doc/JA/syntax/SUMMARY.md b/doc/JA/syntax/SUMMARY.md index c68120a33..83432a7f1 100644 --- a/doc/JA/syntax/SUMMARY.md +++ b/doc/JA/syntax/SUMMARY.md @@ -15,7 +15,7 @@ - [副作用とプロシージャ](./07_side_effect.md) - [プロシージャ](./08_procedure.md) - [組み込みプロシージャ](./09_builtin_procs.md) -- [配列](./10_array.md) +- [リスト](./10_list.md) - [辞書](./11_dict.md) - [添字アクセス](./12_container_ownership.md) - [タプル](./13_tuple.md) diff --git a/doc/JA/syntax/indexes.md b/doc/JA/syntax/indexes.md index ea2ee39e7..6f93aaade 100644 --- a/doc/JA/syntax/indexes.md +++ b/doc/JA/syntax/indexes.md @@ -10,17 +10,17 @@ * ! → [side effect](./07_side_effect.md) * !-type → [mutable type](./type/18_mut.md) -* ? → [error handling](./31_error_handling.md) +* ? → [error handling](./32_error_handling.md) * # → [コメント](./00_basic.md#コメント) * $ → [shared](./type/advanced/shared.md) * % * & * && -* [′ (single quote)](./21_naming_rule.md) +* [′ (single quote)](./22_naming_rule.md) * [" (double quote)](./01_literal.md) * () → [Tuple](./13_tuple.md) * * - * * → [*-less multiplication](./01_literal.md/#less-multiplication) + * * → [*-less multiplication](./01_literal.md#less-multiplication) * + (前置) → [operator](./06_operator.md) * +_ → + (前置) * + (中置) → [operator](./06_operator.md) @@ -30,17 +30,17 @@ * −_ → − (前置) * − (中置) → [operator](./06_operator.md) * − (中置) → [Trait](./type/03_trait.md) - * −> → [anonymous function](./22_lambda.md) -* . → [Visibility](./20_visibility.md) - * [... assignment](./29_spread_syntax.md) - * [... Extract assignment](./29_spread_syntax.md) + * −> → [anonymous function](./23_lambda.md) +* . → [Visibility](./21_visibility.md) + * [... assignment](./30_spread_syntax.md) + * [... Extract assignment](./30_spread_syntax.md) * [... function](./04_function.md) * / * : * : → [Colon application style](./04_function.md) * : → [Declaration](./03_declaration.md) * : → [Keyword Arguments](./04_function.md) - * :: → [visibility](./20_visibility.md) + * :: → [visibility](./21_visibility.md) * := → [default parameters](./04_function.md) * ; * < @@ -53,8 +53,8 @@ * > * >> * >= -* @ → [decorator](./30_decorator.md) -* [] → [Array](./10_array.md) +* @ → [decorator](./31_decorator.md) +* [] → [List](./10_list.md) * \ → [Indention](./00_basic.md) * \ → [Str](./01_literal.md) * ^ @@ -62,7 +62,7 @@ * _ → [Type erasure](./type/advanced/erasure.md) * _+_ → + (infix) * _-_ → − (infix) -* [`` (back quote)](./23_subroutine.md) +* [`` (back quote)](./24_subroutine.md) * {} * [{} type](./type/01_type_system.md) * {:} @@ -82,12 +82,12 @@ * [algebraic type](./type/13_algebraic.md) * [And] * [and] -* [anonymous function](./22_lambda.md) -* [Anonymous polycorrelation coefficient](./22_lambda.md) +* [anonymous function](./23_lambda.md) +* [Anonymous polycorrelation coefficient](./23_lambda.md) * anonymous type → [Type System](./type/01_type_system.md) -* [Array](./10_array.md) +* [List](./10_list.md) * [assert] -* [Attach](./30_decorator.md) +* [Attach](./31_decorator.md) * [attribute](type/09_attributive.md) * [Attribute definitions](./type/02_basic.md) * [Attribute Type](./type/09_attributive.md) @@ -96,7 +96,7 @@ * [Bool, Boolean](./01_literal.md) * [Boolean Object](./01_literal.md) -* [borrow](./19_ownership.md) +* [borrow](./20_ownership.md) ### C @@ -104,24 +104,24 @@ * [Comments](./00_basic.md) * [Complex Object](./01_literal.md) * [Compile-time functions](./04_function.md) -* [circular references](./19_ownership.md) +* [circular references](./20_ownership.md) * [Class](./type/04_class.md) * [Class Relationship](./type/04_class.md) * [Class upcasting](./type/16_subtyping.md) * [Colon application style](./04_function.md) -* [Closure](./24_closure.md) +* [Closure](./25_closure.md) * [Compound Literals](./01_literal.md) * [Complement](./type/13_algebraic.md) -* [Comprehension](./28_comprehension.md) -* [constant](./18_mutability.md) +* [Comprehension](./29_comprehension.md) +* [constant](./19_mutability.md) * [Constants](./02_name.md) -* [Context](./31_error_handling.md) +* [Context](./32_error_handling.md) ### D * [Data type](./type/01_type_system.md) * [Declaration](./03_declaration.md) -* [decorator](./30_decorator.md) +* [decorator](./31_decorator.md) * [Default parameters](./04_function.md) * [Del](./02_name.md) * [Dependent Type](./type/14_dependent.md) @@ -140,10 +140,10 @@ * [Enum Class](./type/04_class.md) * [Enum type](./type/11_enum.md) * [Enumerated, Interval and Refinement Types](./type/12_refinement.md) -* [error handling](./31_error_handling.md) +* [error handling](./32_error_handling.md) * [Existential type](./type/advanced/existential.md) * [Exponential Literal](./01_literal.md) -* [Extract assignment](./29_spread_syntax.md) +* [Extract assignment](./30_spread_syntax.md) ### F @@ -152,14 +152,14 @@ * [for](./05_builtin_funcs.md) * [For-All Patch](./type/07_patch.md) * [For all types](./type/15_quantified.md) -* [freeze](./19_ownership.md) +* [freeze](./20_ownership.md) * [Function](./04_function.md) * [Function definition with multiple patterns](./04_function.md) ### G * [GADTs(Generalized Algebraic Data Types)](./type/advanced/GADTs.md) -* [Generator](./35_generator.md) +* [Generator](./36_generator.md) * [Glue Patch](./type/07_patch.md) ### H @@ -170,21 +170,21 @@ * [id](./09_builtin_procs.md) * [if](./05_builtin_funcs.md) -* [import](./34_package_system.md) -* [impl](./30_decorator.md) +* [import](./35_package_system.md) +* [impl](./31_decorator.md) * [in] * [Indention](./00_basic.md) * [Instant Block](./14_record.md) * [Instance and class attributes](./type/04_class.md) * [Implementing and resolving duplicate traits in the API](type/03_trait.md) -* [inheritable](./30_decorator.md) +* [inheritable](./31_decorator.md) * [inheritance](./type/05_inheritance.md) * [Inheritance of Enumerated Classes](./type/05_inheritance.md) * [Int](./01_literal.md) -* [Integration with Python](./33_integration_with_Python.md) +* [Integration with Python](./34_integration_with_Python.md) * [Interval Type](./type/10_interval.md) * [Intersection](./type/13_algebraic.md) -* [Iterator](./17_iterator.md) +* [Iterator](./18_iterator.md) ### J @@ -195,9 +195,9 @@ ### L -* lambda → [anonymous function](./22_lambda.md) +* lambda → [anonymous function](./23_lambda.md) * let-polymorphism → [rank 1 polymorphism] -* [Literal Identifiers](./21_naming_rule.md) +* [Literal Identifiers](./22_naming_rule.md) * log → [side effect](./07_side_effect.md) ### M @@ -205,13 +205,13 @@ * [match] * [Marker Trait](./type/advanced/marker_trait.md) * [Method](./07_side_effect.md) -* Modifier → [decorator](./30_decorator.md) -* [module](./25_module.md) +* Modifier → [decorator](./31_decorator.md) +* [module](./26_module.md) * [Multiple Inheritance](type/05_inheritance.md) * [Multi-layer (multi-level) Inheritance](type/05_inheritance.md) * [Mutable Type](./type/18_mut.md) * [Mutable Structure Type](./type/advanced/mut_struct.md) -* [Mutability](./18_mutability.md) +* [Mutability](./19_mutability.md) ### N @@ -227,28 +227,28 @@ ### O -* [Object](./26_object_system.md) +* [Object](./27_object_system.md) * [Option] * [Or] * [or] * [Ord] -* [ownership system](./19_ownership.md) +* [ownership system](./20_ownership.md) * [Overloading](./type/advanced/overloading.md) * [Overriding](./type/05_inheritance.md) * [Override in Trait](./type/03_trait.md) ### P -* [Panic](./31_error_handling.md) +* [Panic](./32_error_handling.md) * [Patch](./type/07_patch.md) -* [Pattern match](./27_pattern_matching.md) +* [Pattern match](./28_pattern_matching.md) * [Phantom class](./type/advanced/phantom.md) -* [pipeline operator](./32_pipeline.md) +* [pipeline operator](./33_pipeline.md) * [Predicate](./type/19_bound.md) * [print!] * [Procedures](./08_procedure.md) * [Projection Type](./type/advanced/projection.md) -* Python → [Integration with Python](./33_integration_with_Python.md) +* Python → [Integration with Python](./34_integration_with_Python.md) ### Q @@ -266,9 +266,9 @@ * [Recursive functions](./04_function.md) * [Refinement pattern](./type/12_refinement.md) * [Refinement Type](./type/12_refinement.md) -* [replication](./19_ownership.md) +* [replication](./20_ownership.md) * [Replacing Traits](./type/05_inheritance.md) -* Result → [error handling](./31_error_handling.md) +* Result → [error handling](./32_error_handling.md) * [Rewriting Inherited Attributes](./type/05_inheritance.md) * rootobj @@ -281,9 +281,9 @@ * [Shared Reference](./type/advanced/shared.md) * [side-effect](./07_side_effect.md) * [Smart Cast](./type/12_refinement.md) -* [Spread assignment](./29_spread_syntax.md) +* [Spread assignment](./30_spread_syntax.md) * [special type variables](./type/advanced/special.md) -* [Stack trace](31_error_handling.md) +* [Stack trace](32_error_handling.md) * [Structure type](./type/01_type_system.md) * [Structural Patch](./type/07_patch.md) * [Structural Trait](./type/03_trait.md) @@ -294,11 +294,11 @@ * [Subtyping of subroutines](./type/16_subtyping.md) * [Subtype specification](./type/02_basic.md) * [Subtyping of Polymorphic Function Types](./type/15_quantified.md) -* [Subroutine Signatures](./23_subroutine.md) +* [Subroutine Signatures](./24_subroutine.md) ### T -* [Test](./30_decorator.md) +* [Test](./31_decorator.md) * [Traits](./type/03_trait.md) * [Trait inclusion](./type/03_trait.md) * True → [Boolean Object](./01_literal.md) @@ -342,7 +342,7 @@ * [アサーション] * 値オブジェクト -* [アタッチメントパッチ](./30_decorator.md#attach) +* [アタッチメントパッチ](./31_decorator.md#attach) * アドホック多相 → [オーバーロードの禁止](./type/advanced/overloading.md) * アトリビュート → [属性] * アリティ @@ -386,10 +386,10 @@ * [可変オブジェクト] * [可変型] * [可変参照] - * [可変配列] + * [可変リスト] * [可変長引数] * [関数](./04_function.md) - * [関数型プログラミング](./24_closure.md#可変状態の回避関数型プログラミング) + * [関数型プログラミング](./25_closure.md#可変状態の回避関数型プログラミング) * 基底型 * 記名 * [記名型] → [クラス](./type/04_class.md) @@ -420,7 +420,7 @@ * ~~後方参照~~ → [前方参照] * [コピー] * コメント -* [コレクション](./10_array.md) +* [コレクション](./10_list.md) * コロン → [:] * [コンストラクタ](./type/04_class.md) * コンテナ @@ -436,11 +436,11 @@ * サブスクリプト → [インデックス] * [サブタイピング多相](./type/advanced/overloading.md) * サブルーチン -* [参照](./19_ownership.md#借用) +* [参照](./20_ownership.md#借用) * 参照オブジェクト - * [参照カウント(RC)](./19_ownership.md#複製) + * [参照カウント(RC)](./20_ownership.md#複製) * 参照等価性 → [副作用](./07_side_effect.md) -* [識別子](./02_name.md/#変数) +* [識別子](./02_name.md#変数) * シグネチャ * 型シグネチャ * [辞書](./11_dict.md) @@ -448,7 +448,7 @@ * ジェネリクス → [全称型] * ジェネレータ * [射影型] -* 借用 → [参照](./19_ownership.md#借用) +* 借用 → [参照](./20_ownership.md#借用) * [シャドーイング](./02_name.md#変数) * 種 → [カインド](./type/advanced/kind.md) * [集合] → [セット] @@ -463,7 +463,7 @@ * [スクリプト](./00_basic.md#スクリプト) * スコープ * スプレッド演算子 → [展開代入] -* [スライス](./10_array.md#スライス) +* [スライス](./10_list.md#スライス) * 制御文字 * [整数] → [Int] * [セット](./15_set.md) @@ -488,7 +488,7 @@ * 代数的データ型 * [代入](./02_name.md#変数) * 多重 - * [多重継承](./type/05_inheritance.md/#多重継承の禁止) + * [多重継承](./type/05_inheritance.md#多重継承の禁止) * 多重代入 * 多重定義 → [オーバーロードの禁止] * 多相 @@ -505,13 +505,13 @@ * 抽出代入 * 抽象構文木 → [AST] * 中置演算子 -* [定数](./02_name.md/#定数) +* [定数](./02_name.md#定数) * [定数型](./type/08_value.md) * [定数式](./type/08_value.md) * [定義] * 提供属性 * [適用] -* [デコレータ](./30_decorator.md) +* [デコレータ](./31_decorator.md) * デストラクタ * 手続き → [プロシージャ](./08_procedure.md) * [デフォルト引数](./04_function.md#デフォルト引数) @@ -519,7 +519,7 @@ * [展開演算子] * [展開代入] * [特殊形式](./../API/special.md) -* 匿名関数 → [無名関数](./22_lambda.md) +* 匿名関数 → [無名関数](./23_lambda.md) * ドット演算子(`.`) → [属性参照] * トップ * トップ型 → [Structural Object] @@ -528,26 +528,26 @@ ## な行 -* [内包表記](./28_comprehension.md) +* [内包表記](./29_comprehension.md) * ~~中置(なかおき)演算子~~ → [中置(ちゅうち)演算子] * [名前空間] ## は行 -* [配列](./10_array.md) +* ~~配列~~ → [リスト](./10_list.md) * [派生型](./type/advanced/variance.md#付録-ユーザー定義型の変性) -* [パターン(マッチ)](./27_pattern_matching.md) -* [パッケージ](./34_package_system.md) +* [パターン(マッチ)](./28_pattern_matching.md) +* [パッケージ](./35_package_system.md) * ハッシュマップ → [辞書](./11_dict.md) * [パッチ](./type/07_patch.md) -* パブリック変数 → [公開変数](./20_visibility.md) +* パブリック変数 → [公開変数](./21_visibility.md) * パラメーター → [引数](./04_function.md) * [パラメトリック多相](./type/advanced/overloading.md) * [反変](./type/advanced/variance.md) * 比較 * [比較演算子] * [比較可能型] -* [非公開変数](./20_visibility.md) +* [非公開変数](./21_visibility.md) * 標準 * 標準出力 * 標準入力 @@ -577,12 +577,12 @@ * ~~前置(まえおき)演算子~~ → 前置(ぜんち)演算子 * [マーカー型](./type/advanced/marker_trait.md) -* [無名関数](./22_lambda.md) +* [無名関数](./23_lambda.md) * ミュータブル → [可変性] * ムーブ * メソッド * メタキャラクタ -* [モジュール](./25_module.md) +* [モジュール](./26_module.md) * 文字列 → [Str](./01_literal.md#文字列リテラルstr-literal) * [文字列補間](./01_literal.md#文字列リテラルstr-literal) * 戻り値 @@ -597,11 +597,11 @@ ## ら行 * [ライブラリ] -* ラムダ式 → [無名関数](./22_lambda.md) +* ラムダ式 → [無名関数](./23_lambda.md) * ランク * ランク2多相 * [リテラル](./01_literal.md) - * [リテラル識別子](./21_naming_rule.md#リテラル識別子) + * [リテラル識別子](./22_naming_rule.md#リテラル識別子) * [量化](./type/15_quantified.md) * [レイアウト](./type/18_mut.md) * [列挙型](./type/11_enum.md) @@ -609,7 +609,7 @@ * レコード型 * レコード多相 → [列多相] * [列多相] -* [ローカル変数](./20_visibility.md) +* [ローカル変数](./21_visibility.md) ## わ行 diff --git a/doc/JA/syntax/quick_tour.md b/doc/JA/syntax/quick_tour.md index 870bc81a0..df0c87743 100644 --- a/doc/JA/syntax/quick_tour.md +++ b/doc/JA/syntax/quick_tour.md @@ -227,7 +227,7 @@ right(_, r) = r ### 可変長パターン -後述するタプル/配列/レコードパターンと組み合わせて使う。 +後述するタプル/リスト/レコードパターンと組み合わせて使う。 ```python [i, *j] = [1, 2, 3, 4] @@ -245,7 +245,7 @@ assert first(1, 2, 3) == 1 m, n = 1, 2 ``` -### 配列パターン +### リストパターン ```python length [] = 0 diff --git a/doc/JA/syntax/type/01_type_system.md b/doc/JA/syntax/type/01_type_system.md index 041a05bd5..d0bb3c2dc 100644 --- a/doc/JA/syntax/type/01_type_system.md +++ b/doc/JA/syntax/type/01_type_system.md @@ -47,14 +47,14 @@ Ergでは、記名型はクラスとトレイトがそれに該当します。 記名型全体を表す型(`NominalType`)と構造型全体の型(`StructuralType`)は型全体の型(`Type`)のサブタイプです。 -Ergは型定義に引数(型引数)を渡すことができます。型引数を持つ`Option`, `Array`などを多項カインドと呼びます。これら自体は型ではありませんが、引数を適用することで型となります。また、引数を持たない`Int`, `Str`型などを単純型(スカラー型)と呼びます。 +Ergは型定義に引数(型引数)を渡すことができます。型引数を持つ`Option`, `List`などを多項カインドと呼びます。これら自体は型ではありませんが、引数を適用することで型となります。また、引数を持たない`Int`, `Str`型などを単純型(スカラー型)と呼びます。 型は集合とみなすことができ、包含関係も存在します。例えば`Num`は`Add`や`Sub`などを含んでおり、`Int`は`Nat`を含んでいます。 全てのクラスの上位クラスは`Object == Class {:}`であり、全ての型の下位クラスは`Never == Class {}`です。これについては後述します。 ## 型 -`Array T`のような型は型`T`を引数にとり`Array T`型を返す、つまり`Type -> Type`型の関数とみなせます(型理論的にはカインドともいう)。`Array T`のような型は、特に多相型(Polymorphic Type)と呼び、`Array`そのものは1項カインドといいます。 +`List T`のような型は型`T`を引数にとり`List T`型を返す、つまり`Type -> Type`型の関数とみなせます(型理論的にはカインドともいう)。`List T`のような型は、特に多相型(Polymorphic Type)と呼び、`List`そのものは1項カインドといいます。 引数、戻り値の型が判明している関数の型は`(T, U) -> V`のように表記します。型が同じ2引数関数全体を指定したい場合は`|T| (T, T) -> T`、N引数関数全体を指定したい場合、`Func N`で指定できる。ただし`Func N`型は引数の数や型に関する情報がないので、呼び出すと戻り値はすべて`Obj`型になります。 @@ -62,7 +62,7 @@ Ergは型定義に引数(型引数)を渡すことができます。型引数を `Method`型は第1引数に自身が属するオブジェクト`self`を(参照として)指定する 関数/プロシージャです。依存型においては、メソッド適用後の自身の型も指定できます。これは `T!(!N)`型で`T!(N ~> N-1).() => Int`などのようにメソッドを指定できるということです。 -Ergの配列(Array)はPythonでいうところのリストとなります。`[Int; 3]`は`Int`型オブジェクトが3つ入る配列クラスです。 +Ergの配列(List)はPythonでいうところのリストとなります。`[Int; 3]`は`Int`型オブジェクトが3つ入る配列クラスです。 > __Note__: `(Type; N)`は型であり値でもあるので、このような使い方もできます。 > @@ -114,7 +114,7 @@ Point2D = {.x = Int; .y = Int} 先に述べたように、Ergにおける「型」とは大まかにはオブジェクトの集合を意味します。 以下は`+`(中置演算子)を要求する `Add`型の定義です。`R, O`はいわゆる型引数で、`Int`や`Str`など実装のある型(クラス)が入れられます。他の言語で型引数には特別な記法(ジェネリクス、テンプレートなど)が与えられていますが、Ergでは通常の引数と同じように定義できます。 -なお型引数は型オブジェクト以外も使用できます。例えば配列型`[Int; 3]`は`Array Int, 3`の糖衣文法です。型の実装がかぶる場合、ユーザは明示的に選択しなくてはなりません。 +なお型引数は型オブジェクト以外も使用できます。例えば配列型`[Int; 3]`は`List Int, 3`の糖衣文法です。型の実装がかぶる場合、ユーザは明示的に選択しなくてはなりません。 ```python Add R = Trait { diff --git a/doc/JA/syntax/type/02_basic.md b/doc/JA/syntax/type/02_basic.md index c5acaa01f..7a4a16f34 100644 --- a/doc/JA/syntax/type/02_basic.md +++ b/doc/JA/syntax/type/02_basic.md @@ -19,11 +19,11 @@ j = 1 # 型指定は省略できる ```python # 引数の型指定 -f x, y: Array Int = ... -T X, Y: Array Int = ... +f x, y: List Int = ... +T X, Y: List Int = ... ``` -上の場合、`x, y`は共に`Array Int`であることに注意して下さい。 +上の場合、`x, y`は共に`List Int`であることに注意して下さい。 ```python # 大文字変数の値は定数式でなくてはならない @@ -140,7 +140,7 @@ C:: Id = Int Point3D = {x = Int; y = Int; z = Int} IorS = Int or Str -Vector = Array Int +Vector = List Int ``` またエラー表示の際にも、コンパイラは複合型(上の例の場合、1番目以外の右辺型)にエイリアスが定義されている場合なるべくそれを使用するようになります。 @@ -153,8 +153,8 @@ Vector = Array Int Id = Int UserId = Int # TypeWarning: duplicate aliases: Id and UserId -Ids = Array Id -Ints = Array Int # TypeWarning: duplicate aliases: Isd and Ints +Ids = List Id +Ints = List Int # TypeWarning: duplicate aliases: Isd and Ints IorS = Int or Str IorSorB = IorS or Bool diff --git a/doc/JA/syntax/type/03_trait.md b/doc/JA/syntax/type/03_trait.md index 0f22f6b61..844e5ec5b 100644 --- a/doc/JA/syntax/type/03_trait.md +++ b/doc/JA/syntax/type/03_trait.md @@ -79,7 +79,7 @@ assert Structural(W) == Structural(T.replace {.x = Ratio}) ```python points: [Norm; 2] = [Point2D::new(1, 2), Point2D::new(3, 4)] -assert points.iter().map(x -> x.norm()).collect(Array) == [5, 25] +assert points.iter().map(x -> x.norm()).collect(List) == [5, 25] ``` ## トレイトの包摂 @@ -153,11 +153,11 @@ Mapper T: Type = Trait { .map = (self: Self, T -> U) -> Self.MapIter U } -# ArrayIterator <: Mapper -# ArrayIterator.MapIter == ArrayMapper -# [1, 2, 3].iter(): ArrayIterator Int -# [1, 2, 3].iter().map(x -> "{x}"): ArrayMapper Str -assert [1, 2, 3].iter().map(x -> "\{x}").collect(Array) == ["1", "2", "3"] +# ListIterator <: Mapper +# ListIterator.MapIter == ListMapper +# [1, 2, 3].iter(): ListIterator Int +# [1, 2, 3].iter().map(x -> "{x}"): ListMapper Str +assert [1, 2, 3].iter().map(x -> "\{x}").collect(List) == ["1", "2", "3"] ``` ## トレイトにおけるオーバーライド diff --git a/doc/JA/syntax/type/08_value.md b/doc/JA/syntax/type/08_value.md index 1f68f283c..0ee9e8089 100644 --- a/doc/JA/syntax/type/08_value.md +++ b/doc/JA/syntax/type/08_value.md @@ -14,7 +14,7 @@ Value = ( or Bool or Str or NoneType - or Array Const + or List Const or Tuple Const or Set Const or ConstFunc(Const, _) diff --git a/doc/JA/syntax/type/12_refinement.md b/doc/JA/syntax/type/12_refinement.md index d01880255..d665e5290 100644 --- a/doc/JA/syntax/type/12_refinement.md +++ b/doc/JA/syntax/type/12_refinement.md @@ -12,8 +12,8 @@ Nat = 0.._ Odd = {N: Int | N % 2 == 1} Char = StrWithLen 1 # StrWithLen 1 == {_: StrWithLen N | N == 1} -[Int; 3] == {_: Array Int, N | N == 3} -Array3OrMore == {A: Array _, N | N >= 3} +[Int; 3] == {_: List Int, N | N == 3} +List3OrMore == {A: List _, N | N >= 3} ``` 複数のPredがあるとき、`;`か`and`, `or`で区切れます。`;`と`and`は同じ意味です。 @@ -85,7 +85,7 @@ match i: ```python # メソッド.mは長さ3以上の配列に定義される -Array(T, N | N >= 3) +List(T, N | N >= 3) .m(ref self) = ... ``` diff --git a/doc/JA/syntax/type/14_dependent.md b/doc/JA/syntax/type/14_dependent.md index 3a83c695f..7496ee149 100644 --- a/doc/JA/syntax/type/14_dependent.md +++ b/doc/JA/syntax/type/14_dependent.md @@ -5,7 +5,7 @@ 依存型はErgの最大の特徴とも言っても良い機能です。 依存型とは、値を引数に取る型です。通常の多相型は型のみを引数に取れますが、その制限を緩めたのが依存型といえます。 -依存型は、`[T; N]`(`Array(T, N)`)などがそれに相当します。 +依存型は、`[T; N]`(`List(T, N)`)などがそれに相当します。 この型は、中身の型`T`だけでなく、中身の個数`N`にも依存して決まる型です。`N`には`Nat`型のオブジェクトが入ります。 ```python @@ -69,7 +69,7 @@ vm.stop!() # TypeError: VM!(!"stopped", 1) doesn't have .stop!() 既存の型を組み込んだり継承して依存型を作ることもできます。 ```python -MyArray(T, N) = Inherit [T; N] +MyList(T, N) = Inherit [T; N] # .arrayと連動してself: Self(T, N)の型が変わる MyStruct!(T, N: Nat!) = Class {.array: [T; !N]} @@ -77,7 +77,7 @@ MyStruct!(T, N: Nat!) = Class {.array: [T; !N]} ## 実体指定 -動的配列`arr: [T; !N]`について、処理を進めていくうちに`N`の情報が失われてしまったとします。 +動的リスト`arr: ![T; N]`について、処理を進めていくうちに`N`の情報が失われてしまったとします。 この情報は`assert arr.__len__() == X`とすることで回復させることができます。 ```erg @@ -86,10 +86,10 @@ assert arr.__len__() == 3 arr: [Int; !3] ``` -これは型パラメータの __実体指定__ によって可能となっています。配列型`Array(T, N)`は以下のように定義されています。 +これは型パラメータの __実体指定__ によって可能となっています。配列型`List(T, N)`は以下のように定義されています。 ```erg -Array T <-> Union Self.map(x -> Typeof x), N <-> Self.__len__() = ... +List T <-> Union Self.map(x -> Typeof x), N <-> Self.__len__() = ... ``` `<->`は依存型のパラメータのみで使える特別な記号で、そのパラメータに対する実体を指示します。実体であるところの右辺式は、コンパイル時に計算可能でなくても構いません。コンパイル時情報である`N`と実行時情報である`Self.__len__()`が実体指定を通してリンクされる訳です。 diff --git a/doc/JA/syntax/type/15_quantified.md b/doc/JA/syntax/type/15_quantified.md index 98f6577ca..bd7ce730c 100644 --- a/doc/JA/syntax/type/15_quantified.md +++ b/doc/JA/syntax/type/15_quantified.md @@ -102,7 +102,7 @@ Iterator T = Trait { } it = [1, 2, 3].iter().map i -> i + 1 -it.collect(Array) # [2, 3, 4] +it.collect(List) # [2, 3, 4] ``` 型変数が宣言できるのは`||`の間のみである。ただし、宣言した後はスコープを抜けるまで任意の場所で使用できる。 @@ -281,6 +281,7 @@ DepFn. assert (Int -> Int).type() == Int # by DepFn assert DepFn(Int).type() == Int # by DepFn ``` +
\ No newline at end of file + diff --git a/doc/JA/syntax/type/18_mut.md b/doc/JA/syntax/type/18_mut.md index 0cf1b1f40..40cdb4a3b 100644 --- a/doc/JA/syntax/type/18_mut.md +++ b/doc/JA/syntax/type/18_mut.md @@ -53,14 +53,14 @@ K! T: Type = Class ... 標準ライブラリでは、可変型`(...)!`型は不変型`(...)`型を基底としている場合が多いです。しかし`T!`型と`T`型に言語上特別な関連はなく、そのように構成しなくても構いません[1](#1)。 `T = (...)`のとき単に`T! = (...)!`となる型`(...)`を単純構造型と呼びます。単純構造型は(意味論上)内部構造を持たない型ともいえます。 -配列、タプル、セット、辞書、レコード型は単純構造型ではありませんが、Int型やStr型は単純構造型です。 +リスト、タプル、セット、辞書、レコード型は単純構造型ではありませんが、Int型やStr型は単純構造型です。 以上の説明から、可変型とは自身が可変であるものだけでなく、内部に持つ型が可変であるものも含まれるということになります。 `{x: Int!}`や`[Int!; 3]`などの型は、内部のオブジェクトが可変であり、インスタンス自身が可変なわけではない内部可変型です。 ## Cell! T -Intや配列などの不変型に対しては、既に可変型が定義されています。しかし、このような可変型はどのようにして定義されたのでしょうか?例えば、`{x = Int; y = Int}`型に対しては`{x = Int!; y = Int!}`型などが対応する可変型です。 +Intやリストなどの不変型に対しては、既に可変型が定義されています。しかし、このような可変型はどのようにして定義されたのでしょうか?例えば、`{x = Int; y = Int}`型に対しては`{x = Int!; y = Int!}`型などが対応する可変型です。 しかし`Int!`型はどうやって`Int`型から作られたのでしょうか?あるいは`Int!`型はどのようにして`Int`型と関係付けられているのでしょうか? それらに対する答えが`Cell!`型です。`Cell! T`型は`T`型オブジェクトを格納する箱のような型です。 diff --git a/doc/JA/syntax/type/20_compound.md b/doc/JA/syntax/type/20_compound.md index 874f22b6d..b02ce851f 100644 --- a/doc/JA/syntax/type/20_compound.md +++ b/doc/JA/syntax/type/20_compound.md @@ -27,22 +27,22 @@ また、ユニット型の戻り値は無視できるが、その他のタプル型の戻り値は無視できない。 -## 配列型 +## リスト型 ```erg [], [X; 0], [X; 1], [X; 2], ..., [X; _] == [X] ``` -上の配列型は構文糖であり、`[X; N] == Array X, N`である。 +上のリスト型は構文糖であり、`[X; N] == List X, N`である。 -配列に関してもタプルと同様の部分型規則が存在する。 +リストに関してもタプルと同様の部分型規則が存在する。 ```erg * T <: [] (ユニット規則) * forall N in 0..diff --git a/doc/zh_CN/syntax/type/08_value.md b/doc/zh_CN/syntax/type/08_value.md index 0b99c40e9..f925eb9c5 100644 --- a/doc/zh_CN/syntax/type/08_value.md +++ b/doc/zh_CN/syntax/type/08_value.md @@ -2,7 +2,7 @@ [![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/type/08_value.md%26commit_hash%3Db713e6f5cf9570255ccf44d14166cb2a9984f55a)](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/type/08_value.md&commit_hash=b713e6f5cf9570255ccf44d14166cb2a9984f55a) -值类型是可以在编译时评估的 Erg 内置类型,具体来说: +值类型是可以在编译时评估的 Erg 内置类型,具体来说: ```python Value = ( @@ -14,7 +14,7 @@ Value = ( or Bool or Str or NoneType - or Array Const + or List Const or Tuple Const or Set Const or ConstFunc(Const, _) @@ -38,7 +38,6 @@ Value = ( 1 Erg 中的术语"值类型"与其他语言中的定义不同。纯 Erg 语义中没有内存的概念,并且因为它被放置在堆栈上而说它是值类型,或者因为它实际上是一个指针而说它不是值类型是不正确的。值类型仅表示它是"值"类型或其子类型。[↩](#f1) -
\ No newline at end of file + diff --git a/doc/zh_CN/syntax/type/12_refinement.md b/doc/zh_CN/syntax/type/12_refinement.md index 989ab9437..13a1239c8 100644 --- a/doc/zh_CN/syntax/type/12_refinement.md +++ b/doc/zh_CN/syntax/type/12_refinement.md @@ -12,8 +12,8 @@ Nat = 0.. _ Odd = {N: Int | N % 2 == 1} Char = StrWithLen 1 # StrWithLen 1 == {_: StrWithLen N | N == 1} -[Int; 3] == {_: Array Int, N | N == 3} -Array3OrMore == {A: Array _, N | N >= 3} +[Int; 3] == {_: List Int, N | N == 3} +List3OrMore == {A: List _, N | N >= 3} ``` 当有多个 pred 时,可以用 `;` 或 `and` 或 `or` 分隔。`;` 和 `and` 的意思是一样的 @@ -72,9 +72,10 @@ match i: ```python # 方法 `.m` 是为长度为 3 或更大的数组定义的 -Array(T, N | N >= 3) +List(T, N | N >= 3) .m(&self) = ... ``` + \ No newline at end of file + diff --git a/doc/zh_CN/syntax/type/14_dependent.md b/doc/zh_CN/syntax/type/14_dependent.md index 454dd05b8..c259f0eb9 100644 --- a/doc/zh_CN/syntax/type/14_dependent.md +++ b/doc/zh_CN/syntax/type/14_dependent.md @@ -16,7 +16,7 @@ assert a1 in [Nat; 4] assert a1 + a2 in [Nat; 7] ``` -如果函数参数中传递的类型对象与返回类型有关,则写: +如果函数参数中传递的类型对象与返回类型有关,则写: ```python narray: |N: Nat| {N} -> [{N}; N] @@ -69,11 +69,12 @@ vm.stop!() # 类型错误: VM!(!"stopped", 1) 没有 .stop!() 您还可以嵌入或继承现有类型以创建依赖类型 ```python -MyArray(T, N) = Inherit[T; N] +MyList(T, N) = Inherit[T; N] # self 的类型: Self(T, N) 与 .array 一起变化 MyStruct!(T, N: Nat!) = Class {.array: [T; !N]} ``` + \ No newline at end of file + diff --git a/doc/zh_CN/syntax/type/15_quantified.md b/doc/zh_CN/syntax/type/15_quantified.md index d4881d60d..e77008935 100644 --- a/doc/zh_CN/syntax/type/15_quantified.md +++ b/doc/zh_CN/syntax/type/15_quantified.md @@ -101,7 +101,7 @@ Iterator T = Trait { } it = [1, 2, 3].iter().map i -> i + 1 -it.collect(Array) # [2, 3, 4]. +it.collect(List) # [2, 3, 4]. ``` 类型变量只能在 `||` 期间声明。但是,一旦声明,它们就可以在任何地方使用,直到它们退出作用域 @@ -280,6 +280,7 @@ DepFn. assert (Int -> Int).type() == Int # 由 DepFn assert DepFn(Int).type() == Int # 由 DepFn ``` + \ No newline at end of file + diff --git a/doc/zh_CN/syntax/type/18_mut.md b/doc/zh_CN/syntax/type/18_mut.md index 3dfba1062..22d9246e3 100644 --- a/doc/zh_CN/syntax/type/18_mut.md +++ b/doc/zh_CN/syntax/type/18_mut.md @@ -39,7 +39,7 @@ assert i == 2 ```python a = [1, 2, 3].into [Nat; !3] -x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(Array) +x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(List) ``` 在多态不可变类型中,该类型的类型参数"T"被隐式假定为不可变 @@ -70,19 +70,19 @@ K!T: Type = Class ... ``` 当然,您不必全部记住和使用它们 -对于可变数组类型,只需将 `!` 添加到您想要可变的部分,实际上是 `[T; N]`, `[T!; N]`,`[T; !N]`, ` [T!; !N]` 可以涵盖大多数情况 +对于可变数组类型,只需将 `!` 添加到您想要可变的部分,实际上是 `[T; N]`, `[T!; N]`,`[T; !N]`, `[T!; !N]` 可以涵盖大多数情况 这些数组类型是语法糖,实际类型是: ```python # actually 4 types -[T; N] = Array(T, N) -[T; !N] = Array!(T, !N) -[!T; N] = ArrayWithMutType!(!T, N) -[!T; !N] = ArrayWithMutTypeAndLength!(!T, !N) -[T!; !N] = Array!(T!, !N) -[!T!; N] = ArrayWithMutType!(!T!, N) -[!T!; !N] = ArrayWithMutTypeAndLength!(!T!, !N) +[T; N] = List(T, N) +[T; !N] = List!(T, !N) +[!T; N] = ListWithMutType!(!T, N) +[!T; !N] = ListWithMutTypeAndLength!(!T, !N) +[T!; !N] = List!(T!, !N) +[!T!; N] = ListWithMutType!(!T!, N) +[!T!; !N] = ListWithMutTypeAndLength!(!T!, !N) ``` 这就是能够改变类型的意思 diff --git a/doc/zh_CN/syntax/type/advanced/erasure.md b/doc/zh_CN/syntax/type/advanced/erasure.md index b66ab59fc..b89212300 100644 --- a/doc/zh_CN/syntax/type/advanced/erasure.md +++ b/doc/zh_CN/syntax/type/advanced/erasure.md @@ -20,14 +20,14 @@ g: [T; n] -> [T; _] ```python i: _ # i: Object -[_; _] == [Object; _] == Array +[_; _] == [Object; _] == List ``` 类型擦除与省略类型说明不同。一旦类型参数信息被删除,除非您再次声明它,否则它不会被返回 ```python implicit = (1..5).iter().map(i -> i * 2).to_arr() -explicit = (1..5).iter().map(i -> i * 2).into(Array(Nat)) +explicit = (1..5).iter().map(i -> i * 2).into(List(Nat)) ``` 在 Rust 中,这对应于以下代码: @@ -40,6 +40,6 @@ Erg 不允许部分省略类型,而是使用高阶种类多态性 ```python # collect 是采用 Kind 的高阶 Kind 方法 -hk = (1..5).iter().map(i -> i * 2).collect(Array) -hk: Array(Int) +hk = (1..5).iter().map(i -> i * 2).collect(List) +hk: List(Int) ``` diff --git a/doc/zh_CN/syntax/type/advanced/kind.md b/doc/zh_CN/syntax/type/advanced/kind.md index 14e7875f9..170c6a97a 100644 --- a/doc/zh_CN/syntax/type/advanced/kind.md +++ b/doc/zh_CN/syntax/type/advanced/kind.md @@ -4,7 +4,7 @@ 一切都在 Erg 中输入。类型本身也不例外。__kind__ 表示"类型的类型"。例如,`Int` 属于 `Type`,就像 `1` 属于 `Int`。`Type` 是最简单的一种,__atomic kind__。在类型论符号中,`Type` 对应于 `*` -在Kind的概念中,实际上重要的是一种或多种Kind(多项式Kind)。单项类型,例如`Option`,属于它。一元Kind表示为 `Type -> Type` [1](#1)。诸如 `Array` 或 `Option` 之类的 __container__ 特别是一种以类型作为参数的多项式类型 +在Kind的概念中,实际上重要的是一种或多种Kind(多项式Kind)。单项类型,例如`Option`,属于它。一元Kind表示为 `Type -> Type` [1](#1)。诸如 `List` 或 `Option` 之类的 __container__ 特别是一种以类型作为参数的多项式类型 正如符号 `Type -> Type` 所表明的,`Option` 实际上是一个接收类型 `T` 并返回类型 `Option T` 的函数。但是,由于这个函数不是通常意义上的函数,所以通常称为一元类 注意`->`本身,它是一个匿名函数操作符,当它接收一个类型并返回一个类型时,也可以看作是一Kind型 @@ -30,7 +30,7 @@ K(T). baz self, x = ... # OK ``` -二进制或更高类型的示例是 `{T: U}`(: `(Type, Type) -> Type`), `(T, U, V)`(: `(Type, Type, Type) - > Type `), ... 等等 +二进制或更高类型的示例是 `{T: U}`(: `(Type, Type) -> Type`), `(T, U, V)`(: `(Type, Type, Type) - > Type`), ... 等等 还有一个零项类型`() -> Type`。这有时等同于类型论中的原子类型,但在 Erg 中有所区别。一个例子是`类` @@ -131,6 +131,7 @@ Fn2(T, U). (Int -> Int).f() # 选择了哪一个? ``` + 在上面的示例中,方法 `f` 会选择哪个补丁? 天真,似乎选择了`Fn T`,但是`Fn2 T,U`也是可以的,`Option T`原样包含`T`,所以任何类型都适用,`Container K,T`也匹配`->(Int, Int)`,即 `Container(`->`, Int)` 为 `Int -> Int`。因此,上述所有四个修复程序都是可能的选择 diff --git a/doc/zh_CN/syntax/type/advanced/mut_struct.md b/doc/zh_CN/syntax/type/advanced/mut_struct.md index 1fec66f3d..94109d83b 100644 --- a/doc/zh_CN/syntax/type/advanced/mut_struct.md +++ b/doc/zh_CN/syntax/type/advanced/mut_struct.md @@ -28,7 +28,7 @@ v: [Str; !1]. ``` 对于可变结构类型,可变类型参数用 `!` 标记。在上述情况下,类型 `[Str; !0]` 可以更改为 `[Str; !1]` 等等。即,可以改变长度 -顺便说一句,`[T; !N]` 类型是 `ArrayWithLength!(T, !N)` 类型的糖衣语法 +顺便说一句,`[T; !N]` 类型是 `ListWithLength!(T, !N)` 类型的糖衣语法 可变结构类型当然可以是用户定义的。但是请注意,在构造方法方面与不变结构类型存在一些差异 diff --git a/doc/zh_CN/syntax/type/advanced/quantified_dependent.md b/doc/zh_CN/syntax/type/advanced/quantified_dependent.md index 6794b751b..7733722d0 100644 --- a/doc/zh_CN/syntax/type/advanced/quantified_dependent.md +++ b/doc/zh_CN/syntax/type/advanced/quantified_dependent.md @@ -6,7 +6,7 @@ Erg 有量化和依赖类型。那么很自然地,就可以创建一个将两 ```python NonNullStr = |N: Nat| StrWithLen N | N ! = 0 # 同 {S | N: Nat; S: StrWithLen N; N ! = 0} -NonEmptyArray = |N: Nat| [_; N | N > 0] # 同 {A | N: Nat; A: Array(_, N); N > 0} +NonEmptyList = |N: Nat| [_; N | N > 0] # 同 {A | N: Nat; A: List(_, N); N > 0} ``` 量化依赖类型的标准形式是"K(A, ... | Pred)"。`K` 是类型构造函数,`A, B` 是类型参数,`Pred` 是条件表达式 diff --git a/doc/zh_CN/syntax/type/advanced/variance.md b/doc/zh_CN/syntax/type/advanced/variance.md index 93cbeab09..8d7e26f33 100644 --- a/doc/zh_CN/syntax/type/advanced/variance.md +++ b/doc/zh_CN/syntax/type/advanced/variance.md @@ -7,19 +7,19 @@ Erg 可以对多态类型进行子类型化,但有一些注意事项 首先,考虑普通多态类型的包含关系。一般来说,有一个容器`K`和它分配的类型`A,B`,当`A < B`时,`K A < K B` 例如,`Option Int < Option Object`。因此,在`Option Object`中定义的方法也可以在`Option Int`中使用 -考虑典型的多态类型 `Array!(T)` -请注意,这一次不是 `Array!(T, N)` 因为我们不关心元素的数量 -现在,`Array!(T)` 类型具有称为 `.push!` 和 `.pop!` 的方法,分别表示添加和删除元素。这是类型: +考虑典型的多态类型 `List!(T)` +请注意,这一次不是 `List!(T, N)` 因为我们不关心元素的数量 +现在,`List!(T)` 类型具有称为 `.push!` 和 `.pop!` 的方法,分别表示添加和删除元素。这是类型: -`Array.push!: Self(T).(T) => NoneType` -`Array.pop!: Self(T).() => T` +`List.push!: Self(T).(T) => NoneType` +`List.pop!: Self(T).() => T` 可以直观地理解: -* `Array!(Object).push!(s)` is OK when `s: Str` (just upcast `Str` to `Object`) -* When `o: Object`, `Array!(Str).push!(o)` is NG -* `Array!(Object).pop!().into(Str)` is NG -* `Array!(Str).pop!().into(Object)` is OK +* `List!(Object).push!(s)` is OK when `s: Str` (just upcast `Str` to `Object`) +* When `o: Object`, `List!(Str).push!(o)` is NG +* `List!(Object).pop!().into(Str)` is NG +* `List!(Str).pop!().into(Object)` is OK 就类型系统而言,这是 @@ -65,7 +65,7 @@ Erg 有另一个修改。它是不变的 |A<: T, A :> U| ... ``` -这是使用变量规范的代码示例: +这是使用变量规范的代码示例: ```python show|S <: Show| s: S = log s @@ -81,7 +81,7 @@ List(T). ## 更改规范 `List T` 的例子很棘手,所以让我们更详细一点 -要理解上面的代码,你需要了解多态类型退化。[this section](./variance.md) 中详细讨论了方差,但现在我们需要三个事实: +要理解上面的代码,你需要了解多态类型退化。[this section](./variance.md) 中详细讨论了方差,但现在我们需要三个事实: * 普通的多态类型,例如`List T`,与`T`是协变的(`List U > List T` when `U > T`) * 函数 `T -> U` 对于参数类型 `T` 是逆变的(`(S -> U) < (T -> U)` when `S > T`) @@ -141,4 +141,4 @@ assert InputStream(Str) > InputStream(Object) OutputStream T = Class ..., Impl := Outputs(T) # 输出Str的流也可以认为输出Object assert OutputStream(Str) < OutputStream(Object) -``` \ No newline at end of file +``` diff --git a/doc/zh_TW/API/funcs.md b/doc/zh_TW/API/funcs.md index 288fa980f..42593fd3f 100644 --- a/doc/zh_TW/API/funcs.md +++ b/doc/zh_TW/API/funcs.md @@ -54,7 +54,7 @@ assert True # OK 但是,由于無法比較類,如果要判斷實例,請使用`object in Class`而不是`classof(object) == Class` 編譯時確定的結構類型是通過`Typeof`獲得的 -## Iterator, Array生成系統 +## Iterator, List生成系統 ### repeat|T|(x: T) -> RepeatIterator T @@ -86,7 +86,6 @@ cycle("hello").take 3 # "hellohellohello" 生成新類。 與`Inherit`不同,通過`Class`與基類型(第一個參數`Base`)無關,并且方法丟失。 - ```python C = Class {i = Int} NewInt = Class Int @@ -98,7 +97,6 @@ match jan: _ -> log "Other" ``` - ### Inherit 繼承類可以直接使用父類(`Super`)的方法。可以在第二參數`Layout`中指定新的布局。 diff --git a/doc/zh_TW/API/modules/repl.md b/doc/zh_TW/API/modules/repl.md index ffa1a8425..2a670eb8e 100644 --- a/doc/zh_TW/API/modules/repl.md +++ b/doc/zh_TW/API/modules/repl.md @@ -22,5 +22,5 @@ ```python 1.guess((1,), 2) #diff --git a/doc/zh_TW/syntax/type/08_value.md b/doc/zh_TW/syntax/type/08_value.md index d7f869ecf..7a588cfb4 100644 --- a/doc/zh_TW/syntax/type/08_value.md +++ b/doc/zh_TW/syntax/type/08_value.md @@ -2,7 +2,7 @@ [![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/syntax/type/08_value.md%26commit_hash%3Db713e6f5cf9570255ccf44d14166cb2a9984f55a)](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/type/08_value.md&commit_hash=b713e6f5cf9570255ccf44d14166cb2a9984f55a) -值類型是可以在編譯時評估的 Erg 內置類型,具體來說: +值類型是可以在編譯時評估的 Erg 內置類型,具體來說: ```python Value = ( @@ -14,7 +14,7 @@ Value = ( or Bool or Str or NoneType - or Array Const + or List Const or Tuple Const or Set Const or ConstFunc(Const, _) @@ -38,7 +38,6 @@ Value = ( 1 Erg 中的術語"值類型"與其他語言中的定義不同。純 Erg 語義中沒有內存的概念,并且因為它被放置在堆棧上而說它是值類型,或者因為它實際上是一個指針而說它不是值類型是不正確的。值類型僅表示它是"值"類型或其子類型。[↩](#f1) -
\ No newline at end of file + diff --git a/doc/zh_TW/syntax/type/12_refinement.md b/doc/zh_TW/syntax/type/12_refinement.md index 5e34e3076..0d794a65c 100644 --- a/doc/zh_TW/syntax/type/12_refinement.md +++ b/doc/zh_TW/syntax/type/12_refinement.md @@ -12,8 +12,8 @@ Nat = 0.. _ Odd = {N: Int | N % 2 == 1} Char = StrWithLen 1 # StrWithLen 1 == {_: StrWithLen N | N == 1} -[Int; 3] == {_: Array Int, N | N == 3} -Array3OrMore == {A: Array _, N | N >= 3} +[Int; 3] == {_: List Int, N | N == 3} +List3OrMore == {A: List _, N | N >= 3} ``` 當有多個 pred 時,可以用 `;` 或 `and` 或 `or` 分隔。`;` 和 `and` 的意思是一樣的 @@ -72,9 +72,10 @@ match i: ```python # 方法 `.m` 是為長度為 3 或更大的數組定義的 -Array(T, N | N >= 3) +List(T, N | N >= 3) .m(&self) = ... ``` + \ No newline at end of file + diff --git a/doc/zh_TW/syntax/type/14_dependent.md b/doc/zh_TW/syntax/type/14_dependent.md index 539c17d5a..99c206972 100644 --- a/doc/zh_TW/syntax/type/14_dependent.md +++ b/doc/zh_TW/syntax/type/14_dependent.md @@ -16,7 +16,7 @@ assert a1 in [Nat; 4] assert a1 + a2 in [Nat; 7] ``` -如果函數參數中傳遞的類型對象與返回類型有關,則寫: +如果函數參數中傳遞的類型對象與返回類型有關,則寫: ```python narray: |N: Nat| {N} -> [{N}; N] @@ -69,11 +69,12 @@ vm.stop!() # 類型錯誤: VM!(!"stopped", 1) 沒有 .stop!() 您還可以嵌入或繼承現有類型以創建依賴類型 ```python -MyArray(T, N) = Inherit[T; N] +MyList(T, N) = Inherit[T; N] # self 的類型: Self(T, N) 與 .array 一起變化 MyStruct!(T, N: Nat!) = Class {.array: [T; !N]} ``` + \ No newline at end of file + diff --git a/doc/zh_TW/syntax/type/15_quantified.md b/doc/zh_TW/syntax/type/15_quantified.md index 3e01563eb..d85576f1d 100644 --- a/doc/zh_TW/syntax/type/15_quantified.md +++ b/doc/zh_TW/syntax/type/15_quantified.md @@ -101,7 +101,7 @@ Iterator T = Trait { } it = [1, 2, 3].iter().map i -> i + 1 -it.collect(Array) # [2, 3, 4]. +it.collect(List) # [2, 3, 4]. ``` 類型變量只能在 `||` 期間聲明。但是,一旦聲明,它們就可以在任何地方使用,直到它們退出作用域 @@ -280,6 +280,7 @@ DepFn. assert (Int -> Int).type() == Int # 由 DepFn assert DepFn(Int).type() == Int # 由 DepFn ``` + \ No newline at end of file + diff --git a/doc/zh_TW/syntax/type/18_mut.md b/doc/zh_TW/syntax/type/18_mut.md index a2b9e8e87..aa41f6622 100644 --- a/doc/zh_TW/syntax/type/18_mut.md +++ b/doc/zh_TW/syntax/type/18_mut.md @@ -39,7 +39,7 @@ assert i == 2 ```python a = [1, 2, 3].into [Nat; !3] -x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(Array) +x = a.freeze_map a: [Nat; 3] -> a.iter().map(i -> i + 1).filter(i -> i % 2 == 0).collect(List) ``` 在多態不可變類型中,該類型的類型參數"T"被隱式假定為不可變 @@ -70,19 +70,19 @@ K!T: Type = Class ... ``` 當然,您不必全部記住和使用它們 -對于可變數組類型,只需將 `!` 添加到您想要可變的部分,實際上是 `[T; N]`, `[T!; N]`,`[T; !N]`, ` [T!; !N]` 可以涵蓋大多數情況 +對于可變數組類型,只需將 `!` 添加到您想要可變的部分,實際上是 `[T; N]`, `[T!; N]`,`[T; !N]`, `[T!; !N]` 可以涵蓋大多數情況 這些數組類型是語法糖,實際類型是: ```python # actually 4 types -[T; N] = Array(T, N) -[T; !N] = Array!(T, !N) -[!T; N] = ArrayWithMutType!(!T, N) -[!T; !N] = ArrayWithMutTypeAndLength!(!T, !N) -[T!; !N] = Array!(T!, !N) -[!T!; N] = ArrayWithMutType!(!T!, N) -[!T!; !N] = ArrayWithMutTypeAndLength!(!T!, !N) +[T; N] = List(T, N) +[T; !N] = List!(T, !N) +[!T; N] = ListWithMutType!(!T, N) +[!T; !N] = ListWithMutTypeAndLength!(!T, !N) +[T!; !N] = List!(T!, !N) +[!T!; N] = ListWithMutType!(!T!, N) +[!T!; !N] = ListWithMutTypeAndLength!(!T!, !N) ``` 這就是能夠改變類型的意思 diff --git a/doc/zh_TW/syntax/type/advanced/erasure.md b/doc/zh_TW/syntax/type/advanced/erasure.md index 7bcbad61e..e3d423a60 100644 --- a/doc/zh_TW/syntax/type/advanced/erasure.md +++ b/doc/zh_TW/syntax/type/advanced/erasure.md @@ -20,14 +20,14 @@ g: [T; n] -> [T; _] ```python i: _ # i: Object -[_; _] == [Object; _] == Array +[_; _] == [Object; _] == List ``` 類型擦除與省略類型說明不同。一旦類型參數信息被刪除,除非您再次聲明它,否則它不會被返回 ```python implicit = (1..5).iter().map(i -> i * 2).to_arr() -explicit = (1..5).iter().map(i -> i * 2).into(Array(Nat)) +explicit = (1..5).iter().map(i -> i * 2).into(List(Nat)) ``` 在 Rust 中,這對應于以下代碼: @@ -40,6 +40,6 @@ Erg 不允許部分省略類型,而是使用高階種類多態性 ```python # collect 是采用 Kind 的高階 Kind 方法 -hk = (1..5).iter().map(i -> i * 2).collect(Array) -hk: Array(Int) +hk = (1..5).iter().map(i -> i * 2).collect(List) +hk: List(Int) ``` diff --git a/doc/zh_TW/syntax/type/advanced/kind.md b/doc/zh_TW/syntax/type/advanced/kind.md index 43de7882f..d01e2f2aa 100644 --- a/doc/zh_TW/syntax/type/advanced/kind.md +++ b/doc/zh_TW/syntax/type/advanced/kind.md @@ -4,7 +4,7 @@ 一切都在 Erg 中輸入。類型本身也不例外。__kind__ 表示"類型的類型"。例如,`Int` 屬于 `Type`,就像 `1` 屬于 `Int`。`Type` 是最簡單的一種,__atomic kind__。在類型論符號中,`Type` 對應于 `*` -在Kind的概念中,實際上重要的是一種或多種Kind(多項式Kind)。單項類型,例如`Option`,屬于它。一元Kind表示為 `Type -> Type` [1](#1)。諸如 `Array` 或 `Option` 之類的 __container__ 特別是一種以類型作為參數的多項式類型 +在Kind的概念中,實際上重要的是一種或多種Kind(多項式Kind)。單項類型,例如`Option`,屬于它。一元Kind表示為 `Type -> Type` [1](#1)。諸如 `List` 或 `Option` 之類的 __container__ 特別是一種以類型作為參數的多項式類型 正如符號 `Type -> Type` 所表明的,`Option` 實際上是一個接收類型 `T` 并返回類型 `Option T` 的函數。但是,由于這個函數不是通常意義上的函數,所以通常稱為一元類 注意`->`本身,它是一個匿名函數操作符,當它接收一個類型并返回一個類型時,也可以看作是一Kind型 @@ -30,7 +30,7 @@ K(T). baz self, x = ... # OK ``` -二進制或更高類型的示例是 `{T: U}`(: `(Type, Type) -> Type`), `(T, U, V)`(: `(Type, Type, Type) - > Type `), ... 等等 +二進制或更高類型的示例是 `{T: U}`(: `(Type, Type) -> Type`), `(T, U, V)`(: `(Type, Type, Type) - > Type`), ... 等等 還有一個零項類型`() -> Type`。這有時等同于類型論中的原子類型,但在 Erg 中有所區別。一個例子是`類` @@ -131,6 +131,7 @@ Fn2(T, U). (Int -> Int).f() # 選擇了哪一個? ``` + 在上面的示例中,方法 `f` 會選擇哪個補丁? 天真,似乎選擇了`Fn T`,但是`Fn2 T,U`也是可以的,`Option T`原樣包含`T`,所以任何類型都適用,`Container K,T`也匹配`->(Int, Int)`,即 `Container(`->`, Int)` 為 `Int -> Int`。因此,上述所有四個修復程序都是可能的選擇 diff --git a/doc/zh_TW/syntax/type/advanced/mut_struct.md b/doc/zh_TW/syntax/type/advanced/mut_struct.md index d85d57773..296bf8572 100644 --- a/doc/zh_TW/syntax/type/advanced/mut_struct.md +++ b/doc/zh_TW/syntax/type/advanced/mut_struct.md @@ -28,7 +28,7 @@ v: [Str; !1]. ``` 對于可變結構類型,可變類型參數用 `!` 標記。在上述情況下,類型 `[Str; !0]` 可以更改為 `[Str; !1]` 等等。即,可以改變長度 -順便說一句,`[T; !N]` 類型是 `ArrayWithLength!(T, !N)` 類型的糖衣語法 +順便說一句,`[T; !N]` 類型是 `ListWithLength!(T, !N)` 類型的糖衣語法 可變結構類型當然可以是用戶定義的。但是請注意,在構造方法方面與不變結構類型存在一些差異 diff --git a/doc/zh_TW/syntax/type/advanced/quantified_dependent.md b/doc/zh_TW/syntax/type/advanced/quantified_dependent.md index 8fbddb3c1..747aac968 100644 --- a/doc/zh_TW/syntax/type/advanced/quantified_dependent.md +++ b/doc/zh_TW/syntax/type/advanced/quantified_dependent.md @@ -6,7 +6,7 @@ Erg 有量化和依賴類型。那么很自然地,就可以創建一個將兩 ```python NonNullStr = |N: Nat| StrWithLen N | N ! = 0 # 同 {S | N: Nat; S: StrWithLen N; N ! = 0} -NonEmptyArray = |N: Nat| [_; N | N > 0] # 同 {A | N: Nat; A: Array(_, N); N > 0} +NonEmptyList = |N: Nat| [_; N | N > 0] # 同 {A | N: Nat; A: List(_, N); N > 0} ``` 量化依賴類型的標準形式是"K(A, ... | Pred)"。`K` 是類型構造函數,`A, B` 是類型參數,`Pred` 是條件表達式 diff --git a/doc/zh_TW/syntax/type/advanced/variance.md b/doc/zh_TW/syntax/type/advanced/variance.md index 0083b6b81..4ca980899 100644 --- a/doc/zh_TW/syntax/type/advanced/variance.md +++ b/doc/zh_TW/syntax/type/advanced/variance.md @@ -7,19 +7,19 @@ Erg 可以對多態類型進行子類型化,但有一些注意事項 首先,考慮普通多態類型的包含關系。一般來說,有一個容器`K`和它分配的類型`A,B`,當`A < B`時,`K A < K B` 例如,`Option Int < Option Object`。因此,在`Option Object`中定義的方法也可以在`Option Int`中使用 -考慮典型的多態類型 `Array!(T)` -請注意,這一次不是 `Array!(T, N)` 因為我們不關心元素的數量 -現在,`Array!(T)` 類型具有稱為 `.push!` 和 `.pop!` 的方法,分別表示添加和刪除元素。這是類型: +考慮典型的多態類型 `List!(T)` +請注意,這一次不是 `List!(T, N)` 因為我們不關心元素的數量 +現在,`List!(T)` 類型具有稱為 `.push!` 和 `.pop!` 的方法,分別表示添加和刪除元素。這是類型: -`Array.push!: Self(T).(T) => NoneType` -`Array.pop!: Self(T).() => T` +`List.push!: Self(T).(T) => NoneType` +`List.pop!: Self(T).() => T` 可以直觀地理解: -* `Array!(Object).push!(s)` is OK when `s: Str` (just upcast `Str` to `Object`) -* When `o: Object`, `Array!(Str).push!(o)` is NG -* `Array!(Object).pop!().into(Str)` is NG -* `Array!(Str).pop!().into(Object)` is OK +* `List!(Object).push!(s)` is OK when `s: Str` (just upcast `Str` to `Object`) +* When `o: Object`, `List!(Str).push!(o)` is NG +* `List!(Object).pop!().into(Str)` is NG +* `List!(Str).pop!().into(Object)` is OK 就類型系統而言,這是 @@ -65,7 +65,7 @@ Erg 有另一個修改。它是不變的 |A<: T, A :> U| ... ``` -這是使用變量規范的代碼示例: +這是使用變量規范的代碼示例: ```python show|S <: Show| s: S = log s @@ -81,7 +81,7 @@ List(T). ## 更改規范 `List T` 的例子很棘手,所以讓我們更詳細一點 -要理解上面的代碼,你需要了解多態類型退化。[this section](./variance.md) 中詳細討論了方差,但現在我們需要三個事實: +要理解上面的代碼,你需要了解多態類型退化。[this section](./variance.md) 中詳細討論了方差,但現在我們需要三個事實: * 普通的多態類型,例如`List T`,與`T`是協變的(`List U > List T` when `U > T`) * 函數 `T -> U` 對于參數類型 `T` 是逆變的(`(S -> U) < (T -> U)` when `S > T`) @@ -141,4 +141,4 @@ assert InputStream(Str) > InputStream(Object) OutputStream T = Class ..., Impl := Outputs(T) # 輸出Str的流也可以認為輸出Object assert OutputStream(Str) < OutputStream(Object) -``` \ No newline at end of file +``` diff --git a/examples/array.er b/examples/array.er deleted file mode 100644 index e472fa3cd..000000000 --- a/examples/array.er +++ /dev/null @@ -1,13 +0,0 @@ -arr = [0, 1, 2] -zeros = [0; 3] - -assert arr[0] == 0 -assert zeros[2] == 0 - -print! arr[3] # This will result in a compile-time error! - -mut_arr = ![] -for! 0..<10, i => - mut_arr.push! i - -assert sum(mut_arr) == 45 diff --git a/examples/iterator.er b/examples/iterator.er index 99b0dfcc3..2b99eb435 100644 --- a/examples/iterator.er +++ b/examples/iterator.er @@ -1,16 +1,16 @@ arr as [Nat; 3] = [1, 2, 3] -a2 = arr.map(x -> x + 1).filter(x -> x <= 3).into_array() +a2 = arr.map(x -> x + 1).filter(x -> x <= 3).to_list() assert a2 == [2, 3] -a3 = arr.skip(1).into_array() +a3 = arr.skip(1).to_list() assert a3 == [2, 3] assert arr.nth(0) == 1 -a4 = arr.enumerate().map(((i, x),) -> x + i).into_array() +a4 = arr.enumerate().map(((i, x),) -> x + i).to_list() assert a4 == [1, 3, 5] a5 = arr.reduce 0, (acc, x) -> acc + x assert a5 == 6 assert arr.all x -> x <= 3 assert arr.any x -> x == 2 -a6 = arr.chain(arr).into_array() +a6 = arr.chain(arr).to_list() assert a6 == [1, 2, 3, 1, 2, 3] idx = arr.position i -> i == 2 assert idx == 1 diff --git a/examples/list.er b/examples/list.er index 7325045cf..e472fa3cd 100644 --- a/examples/list.er +++ b/examples/list.er @@ -1,11 +1,13 @@ -IntList = Class NoneType or { .node = Int; .next = IntList } -IntList. - null = IntList None - insert self, node = IntList { .node; .next = self } - fst self = - match self::base: - { node; next = _ } => node - None => None - -l = IntList.null.insert 1 -assert l.fst() == 1 +arr = [0, 1, 2] +zeros = [0; 3] + +assert arr[0] == 0 +assert zeros[2] == 0 + +print! arr[3] # This will result in a compile-time error! + +mut_arr = ![] +for! 0..<10, i => + mut_arr.push! i + +assert sum(mut_arr) == 45 diff --git a/examples/move_check.er b/examples/move_check.er index e894d2b87..8faf95950 100644 --- a/examples/move_check.er +++ b/examples/move_check.er @@ -5,7 +5,7 @@ w = v print! w print! v # this should cause a MoveError -push! |T| a: RefMut(Array!(T, _)), value: T = +push! |T| a: RefMut(List!(T, _)), value: T = a.push! value push! w, 2 diff --git a/examples/mylist.er b/examples/mylist.er new file mode 100644 index 000000000..7325045cf --- /dev/null +++ b/examples/mylist.er @@ -0,0 +1,11 @@ +IntList = Class NoneType or { .node = Int; .next = IntList } +IntList. + null = IntList None + insert self, node = IntList { .node; .next = self } + fst self = + match self::base: + { node; next = _ } => node + None => None + +l = IntList.null.insert 1 +assert l.fst() == 1 diff --git a/tests/should_err/as.er b/tests/should_err/as.er index 747554094..747136abd 100644 --- a/tests/should_err/as.er +++ b/tests/should_err/as.er @@ -6,15 +6,15 @@ _ = n.times! i = n as Int _ = i.times! # ERR -v: Array!(Int or Str, 2) = ![1, 2] +v: List!(Int or Str, 2) = ![1, 2] v.push! 1 # OK v.push! "a" # ERR v.push! None # ERR -v2 as Array!(Int or Str, 2) = ![1, 2] +v2 as List!(Int or Str, 2) = ![1, 2] v2.push! 1 # OK v2.push! "a" # OK v2.push! None # ERR -v3 = v2 as Array!(Int or Str or NoneType, _) +v3 = v2 as List!(Int or Str or NoneType, _) v3.push! None # OK diff --git a/tests/should_err/callable.er b/tests/should_err/callable.er index b58b7f126..c0cd97e3c 100644 --- a/tests/should_err/callable.er +++ b/tests/should_err/callable.er @@ -12,4 +12,4 @@ print! f3(1) 2 # ERR f4 x = (y) => x print! f4(1) 2 # OK -_ = Array() [1, 2] # ERR +_ = List() [1, 2] # ERR diff --git a/tests/should_err/err_loc.er b/tests/should_err/err_loc.er index 986bee406..3529006b1 100644 --- a/tests/should_err/err_loc.er +++ b/tests/should_err/err_loc.er @@ -9,5 +9,5 @@ for! zip([1+1], ["a"+"b"]), ((i, s),) => # i: Nat, s: Str for! {"a": 1}, s => print! s + 1 # ERR -arr as Array(Int) = [1, 2] +arr as List(Int) = [1, 2] _ = all map((i) -> i.method(), arr) # ERR diff --git a/tests/should_err/array_member.er b/tests/should_err/list_member.er similarity index 68% rename from tests/should_err/array_member.er rename to tests/should_err/list_member.er index db8ec62b9..3841337e9 100644 --- a/tests/should_err/array_member.er +++ b/tests/should_err/list_member.er @@ -1,12 +1,12 @@ -C = Class { .a = Array(Int) } +C = Class { .a = List(Int) } _ = C.new { .a = [1] } # OK _ = C.new { .a = ["a"] } # ERR -D = Class { .a = Array(Int, 1) } +D = Class { .a = List(Int, 1) } _ = D.new { .a = [1] } # OK d = D.new { .a = [1, 2] } # OK assert d.a[0] == "a" # ERR -E = Class { .a = Array(Int, 2) } +E = Class { .a = List(Int, 2) } _ = E.new { .a = [1, 2] } # OK _ = E.new { .a = [1] } # ERR diff --git a/tests/should_err/move.er b/tests/should_err/move.er index 30eb2ee52..3aae725de 100644 --- a/tests/should_err/move.er +++ b/tests/should_err/move.er @@ -6,7 +6,7 @@ a.sort! # WARN print! a # ERR v1 = ![] -v2 = v1 as Array!(Int or Str, _) +v2 = v1 as List!(Int or Str, _) v2.push! "a" print! v1 # ERR diff --git a/tests/should_err/mut_array.er b/tests/should_err/mut_list.er similarity index 69% rename from tests/should_err/mut_array.er rename to tests/should_err/mut_list.er index df024d8e6..191034468 100644 --- a/tests/should_err/mut_array.er +++ b/tests/should_err/mut_list.er @@ -12,5 +12,5 @@ i_s.push! "b" i_s.push! 2 i_s.push! None # ERR -_: Array!(Int, _) = !["a"] # ERR -_: Array!(Int, 1) = ![1, 2] # ERR +_: List!(Int, _) = !["a"] # ERR +_: List!(Int, 1) = ![1, 2] # ERR diff --git a/tests/should_err/poly_type_spec.er b/tests/should_err/poly_type_spec.er index 8a8162ab7..55bc1e5cf 100644 --- a/tests/should_err/poly_type_spec.er +++ b/tests/should_err/poly_type_spec.er @@ -1,5 +1,5 @@ -f _: Array!() = None # ERR -g _: Array!(Int, M := 1) = None # ERR -h _: Array!(Int, N := 1, N := 2) = None # ERR +f _: List!() = None # ERR +g _: List!(Int, M := 1) = None # ERR +h _: List!(Int, N := 1, N := 2) = None # ERR _ = f, g, h diff --git a/tests/should_err/side_effect.er b/tests/should_err/side_effect.er index 486a0ecb3..7933384cb 100644 --- a/tests/should_err/side_effect.er +++ b/tests/should_err/side_effect.er @@ -6,10 +6,10 @@ rec = { arr = ![1] # OK -f arr: Array!(Int, _) = +f arr: List!(Int, _) = arr # NG -f2 arr: Array!(Int, _) = +f2 arr: List!(Int, _) = arr.push! 1 # NG g x: Int = diff --git a/tests/should_err/subtyping.er b/tests/should_err/subtyping.er index e6b884acd..1b0d1b88a 100644 --- a/tests/should_err/subtyping.er +++ b/tests/should_err/subtyping.er @@ -66,10 +66,10 @@ i2|T|(x: T): T = _ = i 1 _ = i2 1 # ERR -_: Array!({"a", "b"}, 2) = !["a", "b"] # OK -_: Array!({"a", "b", "c"}, 2) = !["a", "b"] # OK -_: Array!({"a", "c"}, 2) = !["a", "b"] # ERR -_: Array!({"a"}, 2) = !["a", "b"] # ERR +_: List!({"a", "b"}, 2) = !["a", "b"] # OK +_: List!({"a", "b", "c"}, 2) = !["a", "b"] # OK +_: List!({"a", "c"}, 2) = !["a", "b"] # ERR +_: List!({"a"}, 2) = !["a", "b"] # ERR ii _: Iterable(Iterable(Str)) = None ii [1] # ERR diff --git a/tests/should_ok/advanced_type_spec.er b/tests/should_ok/advanced_type_spec.er index cfaf9b9db..cfaa70a85 100644 --- a/tests/should_ok/advanced_type_spec.er +++ b/tests/should_ok/advanced_type_spec.er @@ -5,8 +5,8 @@ add|R: Type, A <: Add(R)|(x: A, y: R): A.Output = x + y f _: Tuple([{B: Bool | B == False} or Str, Int]) = None g _: Tuple([]) = None -_: Iterable(Array(Int, _)) = [[1]] -_: Array(Int, _) = [1] +_: Iterable(List(Int, _)) = [[1]] +_: List(Int, _) = [1] _: Iterable(Dict({Str: Int})) = [{"a": 1}] f2|T|(_: Structural { .a = (self: T) -> Obj }): NoneType = None diff --git a/tests/should_ok/assert_cast.er b/tests/should_ok/assert_cast.er index fb2d307cc..17677023a 100644 --- a/tests/should_ok/assert_cast.er +++ b/tests/should_ok/assert_cast.er @@ -1,29 +1,29 @@ json = pyimport "json" arr = ["a"] -assert arr in Array(Str) -assert arr in Array(Str, 1) -assert arr notin Array(Int) -assert arr notin Array(Str, 2) +assert arr in List(Str) +assert arr in List(Str, 1) +assert arr notin List(Int) +assert arr notin List(Str, 2) j = json.loads "{ \"a\": [1] }" assert j in {Str: Obj} -assert j["a"] in Array(Int) -assert j["a"] notin Array(Str) -_: Array(Int) = j["a"] +assert j["a"] in List(Int) +assert j["a"] notin List(Str) +_: List(Int) = j["a"] k = json.loads "{ \"a\": [1] }" assert k in {Str: Obj} -assert k["a"] notin Array(Str) +assert k["a"] notin List(Str) dic = {"a": "b", "c": "d"} assert dic in {Str: {"b", "d"}} assert dic in {Str: Str} -.f dic: {Str: Str or Array(Str)} = +.f dic: {Str: Str or List(Str)} = assert dic["key"] in Str # Required to pass the check on the next line assert dic["key"] in {"a", "b", "c"} - assert dic["key2"] in Array(Str) + assert dic["key2"] in List(Str) b as Bytes or NoneType = bytes "aaa", "utf-8" _ = if b != None: @@ -42,7 +42,7 @@ assert p! in (*objs: Obj) => NoneType p!("OK") xs: [Nat or NoneType; _] = [1, None, 2] -ys: [Nat; _] = array filter x -> x != None, xs +ys: [Nat; _] = list filter x -> x != None, xs nats _: [Nat; _] = None nats ys diff --git a/tests/should_ok/closure.er b/tests/should_ok/closure.er index 95d033f5c..428603e3f 100644 --- a/tests/should_ok/closure.er +++ b/tests/should_ok/closure.er @@ -1,4 +1,4 @@ -func vers: Array(Int), version: Int = +func vers: List(Int), version: Int = all map(v -> v == version, vers) assert func([1, 1], 1) @@ -23,7 +23,7 @@ for! [1], _ => {SemVer;} = import "semver" -Versions! = Class Dict! { Str: Array!(SemVer) } +Versions! = Class Dict! { Str: List!(SemVer) } Versions!. new() = Versions! !{:} insert!(ref! self, name: Str, version: SemVer) = @@ -41,7 +41,7 @@ _ = vs.insert! "foo", SemVer.from_str "1.0.1" Triple = Class { .version = SemVer; } Triple. new version = Triple { .version; } -.Version! = Class Dict! { Str: Array!(Triple) } +.Version! = Class Dict! { Str: List!(Triple) } .Version!. new!() = .Version! !{ "a" : ![Triple.new(SemVer.from_str("0.1.0"))] } insert!(ref! self, name: Str, version: SemVer) = diff --git a/tests/should_ok/container_class.er b/tests/should_ok/container_class.er index fbf214579..a7f4c4f6f 100644 --- a/tests/should_ok/container_class.er +++ b/tests/should_ok/container_class.er @@ -6,11 +6,11 @@ D! = Class Dict! { Int: [Str; _] } _ = D!.new !{:} _ = D!.new !{1: ["a"]} -D2 = Class { Str: Array(Int) } +D2 = Class { Str: List(Int) } _ = D2.new { "a": [1] } -D3 = Class { Str: Array!(Int) } +D3 = Class { Str: List!(Int) } _ = D3.new { "a": ![1] } -D4! = Class Dict! { Str: Array!(Int) } +D4! = Class Dict! { Str: List!(Int) } _ = D4!.new !{ "a": ![1] } diff --git a/tests/should_ok/dyn_type_check.er b/tests/should_ok/dyn_type_check.er index ed4cece41..38358e924 100644 --- a/tests/should_ok/dyn_type_check.er +++ b/tests/should_ok/dyn_type_check.er @@ -10,11 +10,11 @@ assert dic2 in {Str or Int: Int} assert dic2 in {Str: Int or Str} assert dic2 notin {Int: Int} dic3 = {"a": "b"} -assert dic3 in {Str: Str or Array(Str) or Record} +assert dic3 in {Str: Str or List(Str) or Record} dic4 = {"a": ["b"]} -assert dic4 in {Str: Str or Array(Str) or Record} +assert dic4 in {Str: Str or List(Str) or Record} dic5 = {"a": {a = 1}} -assert dic5 in {Str: Str or Array(Str) or Record} +assert dic5 in {Str: Str or List(Str) or Record} tup = () assert tup in () diff --git a/tests/should_ok/infer_method.er b/tests/should_ok/infer_method.er index 966320931..6cd92e8cf 100644 --- a/tests/should_ok/infer_method.er +++ b/tests/should_ok/infer_method.er @@ -1,5 +1,5 @@ {SemVer;} = import "semver" -.func vers: Array(SemVer), version: SemVer = +.func vers: List(SemVer), version: SemVer = if all(map((v) -> v.compatible_with(version), vers)): do: todo() diff --git a/tests/should_ok/array.er b/tests/should_ok/list.er similarity index 93% rename from tests/should_ok/array.er rename to tests/should_ok/list.er index 10ed09adc..6e363209d 100644 --- a/tests/should_ok/array.er +++ b/tests/should_ok/list.er @@ -36,5 +36,5 @@ assert l == [] l2 = [![1]].repeat 3 l2[0].push! 2 -ans: Array(Array(Nat)) = [[1, 2], [1], [1]] +ans: List(List(Nat)) = [[1, 2], [1], [1]] assert l2 == ans diff --git a/tests/should_ok/array_member.er b/tests/should_ok/list_member.er similarity index 56% rename from tests/should_ok/array_member.er rename to tests/should_ok/list_member.er index 1d6b760fc..e626f5cf3 100644 --- a/tests/should_ok/array_member.er +++ b/tests/should_ok/list_member.er @@ -1,3 +1,3 @@ -D = Class { .a = Array(Int, 1) } +D = Class { .a = List(Int, 1) } d = D.new { .a = [1] } assert d.a[0] == 1 diff --git a/tests/should_ok/map.er b/tests/should_ok/map.er index 0a3425d67..356d020b0 100644 --- a/tests/should_ok/map.er +++ b/tests/should_ok/map.er @@ -1,7 +1,7 @@ id x = x -ids = Array.__call__(map(id, ["1", "2", "3"])) -ints = Array.__call__(map(int, ["1", "2", "3"])) +ids = List.__call__(map(id, ["1", "2", "3"])) +ints = List.__call__(map(int, ["1", "2", "3"])) assert ids == ["1", "2", "3"] assert ints == [1, 2, 3] diff --git a/tests/should_ok/mut_array.er b/tests/should_ok/mut_list.er similarity index 65% rename from tests/should_ok/mut_array.er rename to tests/should_ok/mut_list.er index 737a032c7..13ab4dac7 100644 --- a/tests/should_ok/mut_array.er +++ b/tests/should_ok/mut_list.er @@ -1,4 +1,4 @@ -v as Array!(Nat, _) = ![] +v as List!(Nat, _) = ![] for! 0..<10, i => v.push! i @@ -6,12 +6,12 @@ assert v[0] == 0 assert v == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] log sum v -iv: Array!(Int, _) = ![1] +iv: List!(Int, _) = ![1] iv.push! 2 -iv: Array!(Int, 2) +iv: List!(Int, 2) v2 = ![1, 1, 1] v2.update!((x: [{1}; _]) -> x + [1]) -v3 as Array!(Int, _) = ![1, 2, 3] +v3 as List!(Int, _) = ![1, 2, 3] v3.update!(x -> x + [1]) diff --git a/tests/should_ok/poly_type_spec.er b/tests/should_ok/poly_type_spec.er index 1aedeb3db..ebf8e6574 100644 --- a/tests/should_ok/poly_type_spec.er +++ b/tests/should_ok/poly_type_spec.er @@ -1,6 +1,6 @@ -f _: Array!(Int, _) = None -g _: Array!(Int) = None -h _: Array!(Int, N := 1) = None +f _: List!(Int, _) = None +g _: List!(Int) = None +h _: List!(Int, N := 1) = None f ![1, 2] g ![1, 2] diff --git a/tests/should_ok/subtyping.er b/tests/should_ok/subtyping.er index 247dce9e7..3b9c8974f 100644 --- a/tests/should_ok/subtyping.er +++ b/tests/should_ok/subtyping.er @@ -14,9 +14,9 @@ str_to_int_or_rec { "a": 1 } str_to_int_or_rec { "a": {.a = 1} } str_to_int_or_rec { "a": {.a = 1}, "b": 1 } -_ as Array(Array(Int)) = ![![1]] -_ as Array(Array(Int, 1), 1) = ![![1]] -_ as Array(Array!(Int, 1), 1) = ![![1]] -_ as Array!(Array(Int, 1), 1) = ![![1]] -_ as Array!(Array!(Int, 1), 1) = ![![1]] -_ as Array!(Array!({1}, 1), 1) = ![![1]] +_ as List(List(Int)) = ![![1]] +_ as List(List(Int, 1), 1) = ![![1]] +_ as List(List!(Int, 1), 1) = ![![1]] +_ as List!(List(Int, 1), 1) = ![![1]] +_ as List!(List!(Int, 1), 1) = ![![1]] +_ as List!(List!({1}, 1), 1) = ![![1]] diff --git a/tests/test.rs b/tests/test.rs index 8cebdf41f..9e79e8daa 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -17,13 +17,13 @@ fn exec_advanced_type_spec() -> Result<(), ()> { } #[test] -fn exec_array() -> Result<(), ()> { - expect_success("tests/should_ok/array.er", 0) +fn exec_list_test() -> Result<(), ()> { + expect_success("tests/should_ok/list.er", 0) } #[test] -fn exec_array_member() -> Result<(), ()> { - expect_success("tests/should_ok/array_member.er", 0) +fn exec_list_member() -> Result<(), ()> { + expect_success("tests/should_ok/list_member.er", 0) } #[test] @@ -237,11 +237,6 @@ fn exec_iterator_test() -> Result<(), ()> { expect_success("tests/should_ok/iterator.er", 0) } -#[test] -fn exec_list() -> Result<(), ()> { - expect_success("examples/list.er", 0) -} - #[test] fn exec_long() -> Result<(), ()> { expect_success("tests/should_ok/long.er", 257) @@ -288,8 +283,8 @@ fn exec_mut() -> Result<(), ()> { } #[test] -fn exec_mut_array() -> Result<(), ()> { - expect_success("tests/should_ok/mut_array.er", 0) +fn exec_mut_list() -> Result<(), ()> { + expect_success("tests/should_ok/mut_list.er", 0) } #[test] @@ -297,6 +292,11 @@ fn exec_mut_dict() -> Result<(), ()> { expect_success("tests/should_ok/mut_dict.er", 0) } +#[test] +fn exec_mylist() -> Result<(), ()> { + expect_success("examples/mylist.er", 0) +} + #[test] fn exec_nested() -> Result<(), ()> { expect_success("tests/should_ok/nested.er", 3) @@ -488,13 +488,13 @@ fn exec_args() -> Result<(), ()> { } #[test] -fn exec_array_err() -> Result<(), ()> { - expect_failure("examples/array.er", 0, 1) +fn exec_list_err() -> Result<(), ()> { + expect_failure("examples/list.er", 0, 1) } #[test] -fn exec_array_member_err() -> Result<(), ()> { - expect_failure("tests/should_err/array_member.er", 0, 3) +fn exec_list_member_err() -> Result<(), ()> { + expect_failure("tests/should_err/list_member.er", 0, 3) } #[test] @@ -659,8 +659,8 @@ fn exec_mut_err() -> Result<(), ()> { } #[test] -fn exec_mut_array_err() -> Result<(), ()> { - expect_failure("tests/should_err/mut_array.er", 0, 5) +fn exec_mut_list_err() -> Result<(), ()> { + expect_failure("tests/should_err/mut_list.er", 0, 5) } #[test]