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 Server { calls } Expr::UnaryOp(unop) => self.gen_outgoing_call(&unop.expr), - Expr::Array(Array::Normal(arr)) => { - for arg in arr.elems.pos_args.iter() { + Expr::List(List::Normal(lis)) => { + for arg in lis.elems.pos_args.iter() { calls.extend(self.gen_outgoing_call(&arg.expr)); } calls diff --git a/crates/els/hir_visitor.rs b/crates/els/hir_visitor.rs index 26e1aa422..fc803bde9 100644 --- a/crates/els/hir_visitor.rs +++ b/crates/els/hir_visitor.rs @@ -142,7 +142,7 @@ impl<'a> HIRVisitor<'a> { | Expr::Accessor(_) | Expr::BinOp(_) | Expr::UnaryOp(_) - | Expr::Array(_) + | Expr::List(_) | Expr::Dict(_) | Expr::Set(_) | Expr::Tuple(_) @@ -275,7 +275,7 @@ impl<'a> HIRVisitor<'a> { Expr::Def(def) => self.get_expr_from_def(expr, def, pos), Expr::PatchDef(patch_def) => self.get_expr_from_patch_def(expr, patch_def, pos), Expr::Lambda(lambda) => self.get_expr_from_lambda(expr, lambda, pos), - Expr::Array(arr) => self.get_expr_from_array(expr, arr, pos), + Expr::List(lis) => self.get_expr_from_list(expr, lis, pos), Expr::Dict(dict) => self.get_expr_from_dict(expr, dict, pos), Expr::Record(record) => self.get_expr_from_record(expr, record, pos), Expr::Set(set) => self.get_expr_from_set(expr, set, pos), @@ -440,18 +440,18 @@ impl<'a> HIRVisitor<'a> { self.get_expr_from_block(lambda.body.iter(), pos) } - fn get_expr_from_array<'e>( + fn get_expr_from_list<'e>( &'e self, expr: &'e Expr, - arr: &'e Array, + lis: &'e List, pos: Position, ) -> Option<&Expr> { - if arr.ln_end() == pos.ln_end() && self.search.matches(expr) { + if lis.ln_end() == pos.ln_end() && self.search.matches(expr) { // arr: `[1, 2]`, pos: `]` return Some(expr); } - match arr { - Array::Normal(arr) => self.get_expr_from_args(&arr.elems, pos), + match lis { + List::Normal(lis) => self.get_expr_from_args(&lis.elems, pos), _ => None, // todo!(), } } @@ -587,7 +587,7 @@ impl<'a> HIRVisitor<'a> { Expr::PatchDef(patch_def) => self.get_patch_def_info(patch_def, token), Expr::Def(def) => self.get_def_info(def, token), Expr::Lambda(lambda) => self.get_lambda_info(lambda, token), - Expr::Array(arr) => self.get_array_info(arr, token), + Expr::List(lis) => self.get_list_info(lis, token), Expr::Dict(dict) => self.get_dict_info(dict, token), Expr::Record(record) => self.get_record_info(record, token), Expr::Set(set) => self.get_set_info(set, token), @@ -764,9 +764,9 @@ impl<'a> HIRVisitor<'a> { .or_else(|| self.get_block_info(lambda.body.iter(), token)) } - fn get_array_info(&self, arr: &Array, token: &Token) -> Option { - match arr { - Array::Normal(arr) => self.get_args_info(&arr.elems, token), + fn get_list_info(&self, lis: &List, token: &Token) -> Option { + match lis { + List::Normal(lis) => self.get_args_info(&lis.elems, token), _ => None, // todo!(), } } diff --git a/crates/els/server.rs b/crates/els/server.rs index 9868601c8..9890a9583 100644 --- a/crates/els/server.rs +++ b/crates/els/server.rs @@ -272,12 +272,12 @@ impl Server { lsp_log!("failed to get packages: {}", artifact.ast); return cfg; }; - let Some(ast::Expr::Array(ast::Array::Normal(arr))) = pkgs.body.block.first() else { + let Some(ast::Expr::List(ast::List::Normal(lis))) = pkgs.body.block.first() else { lsp_log!("packages must be an array: {pkgs}"); return cfg; }; let mut packages = vec![]; - for rec in arr.iter() { + for rec in lis.iter() { let ast::Expr::Record(rec) = rec else { lsp_log!("packages must be records: {rec}"); break; diff --git a/crates/erg_compiler/codegen.rs b/crates/erg_compiler/codegen.rs index 85babbe3b..84162a6e1 100644 --- a/crates/erg_compiler/codegen.rs +++ b/crates/erg_compiler/codegen.rs @@ -35,11 +35,11 @@ use erg_parser::token::{Token, TokenKind}; use crate::compile::{AccessKind, Name, StoreLoadKind}; use crate::context::ControlKind; use crate::error::CompileError; -use crate::hir::ArrayWithLength; use crate::hir::DefaultParamSignature; +use crate::hir::ListWithLength; use crate::hir::{ - Accessor, Args, Array, BinOp, Block, Call, ClassDef, Def, DefBody, Expr, GuardClause, - Identifier, Lambda, Literal, NonDefaultParamSignature, Params, PatchDef, PosArg, ReDef, Record, + Accessor, Args, BinOp, Block, Call, ClassDef, Def, DefBody, Expr, GuardClause, Identifier, + Lambda, List, Literal, NonDefaultParamSignature, Params, PatchDef, PosArg, ReDef, Record, Signature, SubrSignature, Tuple, UnaryOp, VarSignature, HIR, }; use crate::ty::codeobj::{CodeObj, CodeObjFlags, MakeFunctionFlags}; @@ -3031,20 +3031,20 @@ impl PyCodeGenerator { } // TODO: list comprehension - fn emit_array(&mut self, array: Array) { + fn emit_list(&mut self, list: List) { let init_stack_len = self.stack_len(); if !self.cfg.no_std { self.emit_push_null(); - if array.is_unsized() { - self.emit_load_name_instr(Identifier::static_public("UnsizedArray")); + if list.is_unsized() { + self.emit_load_name_instr(Identifier::static_public("UnsizedList")); } else { - self.emit_load_name_instr(Identifier::static_public("Array")); + self.emit_load_name_instr(Identifier::static_public("List")); } } - match array { - Array::Normal(mut arr) => { - let len = arr.elems.len(); - while let Some(arg) = arr.elems.try_remove_pos(0) { + match list { + List::Normal(mut lis) => { + let len = lis.elems.len(); + while let Some(arg) = lis.elems.try_remove_pos(0) { self.emit_expr(arg.expr); } self.write_instr(BUILD_LIST); @@ -3055,7 +3055,7 @@ impl PyCodeGenerator { self.stack_dec_n(len - 1); } } - Array::WithLength(ArrayWithLength { + List::WithLength(ListWithLength { elem, len: Some(len), .. @@ -3066,10 +3066,10 @@ impl PyCodeGenerator { self.emit_call_instr(1, Name); self.stack_dec(); self.emit_expr(*len); - self.emit_binop_instr(Token::dummy(TokenKind::Star, "*"), TypePair::ArrayNat); + self.emit_binop_instr(Token::dummy(TokenKind::Star, "*"), TypePair::ListNat); return; } - Array::WithLength(ArrayWithLength { + List::WithLength(ListWithLength { elem, len: None, .. }) => { self.emit_expr(*elem); @@ -3331,7 +3331,7 @@ impl PyCodeGenerator { Expr::UnaryOp(unary) => self.emit_unaryop(unary), Expr::BinOp(bin) => self.emit_binop(bin), Expr::Call(call) => self.emit_call(call), - Expr::Array(arr) => self.emit_array(arr), + Expr::List(lis) => self.emit_list(lis), Expr::Tuple(tup) => self.emit_tuple(tup), Expr::Set(set) => self.emit_set(set), Expr::Dict(dict) => self.emit_dict(dict), @@ -3355,7 +3355,7 @@ impl PyCodeGenerator { self.emit_load_name_instr(Identifier::public(&v.qual_name())); } other => match &other.qual_name()[..] { - t @ ("Bytes" | "Array" | "Dict" | "Set") => { + t @ ("Bytes" | "List" | "Dict" | "Set") => { self.emit_push_null(); self.emit_load_name_instr(Identifier::public(t)); } @@ -3378,7 +3378,7 @@ impl PyCodeGenerator { Expr::UnaryOp(unary) => self.emit_unaryop(unary), Expr::BinOp(bin) => self.emit_binop(bin), Expr::Call(call) => self.emit_call(call), - Expr::Array(arr) => self.emit_array(arr), + Expr::List(lis) => self.emit_list(lis), Expr::Tuple(tup) => self.emit_tuple(tup), Expr::Set(set) => self.emit_set(set), Expr::Dict(dict) => self.emit_dict(dict), diff --git a/crates/erg_compiler/context/compare.rs b/crates/erg_compiler/context/compare.rs index b54705f3f..6a6cad588 100644 --- a/crates/erg_compiler/context/compare.rs +++ b/crates/erg_compiler/context/compare.rs @@ -192,7 +192,7 @@ impl Context { .. }), ) if &n[..] == "GenericProc" => (Absolutely, true), - (Mono(l), Poly { name: r, .. }) if &l[..] == "GenericArray" && &r[..] == "Array" => { + (Mono(l), Poly { name: r, .. }) if &l[..] == "GenericList" && &r[..] == "List" => { (Absolutely, true) } (Mono(l), Poly { name: r, .. }) if &l[..] == "GenericDict" && &r[..] == "Dict" => { @@ -494,8 +494,8 @@ impl Context { } else if let Some(lfvt) = lfv.get_type() { // e.g. lfv: ?L(: Int) is unreachable // but - // ?L(: Array(Type, 3)) :> Array(Int, 3) - // => Array(Type, 3) :> Array(Typeof(Int), 3) + // ?L(: List(Type, 3)) :> List(Int, 3) + // => List(Type, 3) :> List(Typeof(Int), 3) // => true let rhs_meta = self.meta_type(rhs); self.supertype_of(&lfvt, &rhs_meta) @@ -568,7 +568,7 @@ impl Context { self.convert_tp_into_value(params[0].clone()).is_ok() } (ty @ (Type | ClassType | TraitType), Poly { name, params }) - if &name[..] == "Array" || &name[..] == "UnsizedArray" || &name[..] == "Set" => + if &name[..] == "List" || &name[..] == "UnsizedList" || &name[..] == "Set" => { let Ok(elem_t) = self.convert_tp_into_type(params[0].clone()) else { return false; @@ -666,8 +666,8 @@ impl Context { // Int :> {I: Str| ...} == false // Bool :> {1} == true // Bool :> {2} == false - // [2, 3]: {A: Array(Nat) | A.prod() == 6} - // Array({1, 2}, _) :> {[3, 4]} == false + // [2, 3]: {A: List(Nat) | A.prod() == 6} + // List({1, 2}, _) :> {[3, 4]} == false (l, Refinement(r)) => { // Type / {S: Set(Str) | S == {"a", "b"}} // TODO: GeneralEq @@ -698,7 +698,7 @@ impl Context { // {N: Nat | ...} :> Int) == false // ({I: Int | I >= 0} :> Int) == false // {U(: Type)} :> { .x = {Int} }(== {{ .x = Int }}) == true - // {[1]} == Array({1}, 1) :> Array({1}, _) == true + // {[1]} == List({1}, 1) :> List({1}, _) == true (Refinement(l), r) => { if let Some(r) = r.to_singleton() { return self.structural_supertype_of(lhs, &Type::Refinement(r)); @@ -804,7 +804,7 @@ impl Context { return false; } // [Int; 2] :> [Int; 3] - if &ln[..] == "Array" || &ln[..] == "Set" { + if &ln[..] == "List" || &ln[..] == "Set" { let Ok(lt) = self.convert_tp_into_type(lparams[0].clone()) else { return false; }; @@ -941,7 +941,7 @@ impl Context { self.supertype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t) } }, - (TyParam::Array(sup), TyParam::Array(sub)) + (TyParam::List(sup), TyParam::List(sub)) | (TyParam::Tuple(sup), TyParam::Tuple(sub)) => { if sup.len() > sub.len() || (variance.is_invariant() && sup.len() != sub.len()) { return false; @@ -991,7 +991,7 @@ impl Context { } true } - (TyParam::UnsizedArray(sup), TyParam::UnsizedArray(sub)) => { + (TyParam::UnsizedList(sup), TyParam::UnsizedList(sub)) => { self.supertype_of_tp(sup, sub, variance) } (TyParam::Type(sup), TyParam::Type(sub)) => match variance { @@ -1308,8 +1308,8 @@ impl Context { /// union(Nat, Int) == Int /// union(Int, Str) == Int or Str /// union(?T(<: Str), ?U(<: Int)) == ?T or ?U - /// union(Array(Int, 2), Array(Str, 2)) == Array(Int or Str, 2) - /// union(Array(Int, 2), Array(Str, 3)) == Array(Int, 2) or Array(Int, 3) + /// union(List(Int, 2), List(Str, 2)) == List(Int or Str, 2) + /// union(List(Int, 2), List(Str, 3)) == List(Int, 2) or List(Int, 3) /// union({ .a = Int }, { .a = Str }) == { .a = Int or Str } /// union({ .a = Int }, { .a = Int; .b = Int }) == { .a = Int } or { .a = Int; .b = Int } # not to lost `b` information /// union((A and B) or C) == (A or C) and (B or C) @@ -1387,7 +1387,7 @@ impl Context { t } (t, Type::Never) | (Type::Never, t) => t.clone(), - // Array({1, 2}, 2), Array({3, 4}, 2) ==> Array({1, 2, 3, 4}, 2) + // List({1, 2}, 2), List({3, 4}, 2) ==> List({1, 2, 3, 4}, 2) ( Type::Poly { name: ln, @@ -1430,7 +1430,7 @@ impl Context { Some(TyParam::t(self.union(l, r.typ()))) } (TyParam::Type(l), TyParam::Type(r)) => Some(TyParam::t(self.union(l, r))), - (TyParam::Array(l), TyParam::Array(r)) => { + (TyParam::List(l), TyParam::List(r)) => { let mut tps = vec![]; for (l, r) in l.iter().zip(r.iter()) { if let Some(tp) = self.union_tp(l, r) { @@ -1439,7 +1439,7 @@ impl Context { return None; } } - Some(TyParam::Array(tps)) + Some(TyParam::List(tps)) } (fv @ TyParam::FreeVar(f), other) | (other, fv @ TyParam::FreeVar(f)) if f.is_unbound() => @@ -2195,7 +2195,7 @@ impl Context { } } - /// {[]} == {A: Array(Never, _) | A == []} => Array(Never, 0) + /// {[]} == {A: List(Never, _) | A == []} => List(Never, 0) pub(crate) fn refinement_to_poly(&self, refine: &RefinementType) -> Option { if refine.t.is_monomorphic() { return None; @@ -2207,7 +2207,7 @@ impl Context { return None; } match &refine.t.qual_name()[..] { - "Array" => self.get_tp_t(rhs).ok().map(|t| t.derefine()), + "List" => self.get_tp_t(rhs).ok().map(|t| t.derefine()), _ => None, } } diff --git a/crates/erg_compiler/context/eval.rs b/crates/erg_compiler/context/eval.rs index dcd4808a7..f17098a00 100644 --- a/crates/erg_compiler/context/eval.rs +++ b/crates/erg_compiler/context/eval.rs @@ -20,9 +20,9 @@ use erg_parser::desugar::Desugarer; use erg_parser::token::{Token, TokenKind}; use crate::ty::constructors::{ - array_t, bounded, closed_range, dict_t, func, guard, mono, mono_q, named_free_var, poly, proj, + bounded, closed_range, dict_t, func, guard, list_t, mono, mono_q, named_free_var, poly, proj, proj_call, ref_, ref_mut, refinement, set_t, subr_t, subtypeof, tp_enum, try_v_enum, tuple_t, - unknown_len_array_t, v_enum, + unknown_len_list_t, v_enum, }; use crate::ty::free::HasLevel; use crate::ty::typaram::{OpKind, TyParam}; @@ -154,13 +154,13 @@ impl<'c> Substituter<'c> { /// e.g. /// ```erg - /// qt: Array(T, N), st: Array(Int, 3) + /// qt: List(T, N), st: List(Int, 3) /// qt: T or NoneType, st: NoneType or Int (T == Int) /// ``` /// invalid (no effect): /// ```erg - /// qt: Iterable(T), st: Array(Int, 3) - /// qt: Array(T, N), st: Array!(Int, 3) # TODO + /// qt: Iterable(T), st: List(Int, 3) + /// qt: List(T, N), st: List!(Int, 3) # TODO /// ``` pub(crate) fn substitute_typarams( ctx: &'c Context, @@ -282,9 +282,9 @@ impl<'c> Substituter<'c> { if !qt.is_undoable_linked_var() && qt.is_generalized() && qt.is_free_var() { qt.undoable_link(&st, &self.undoable_linked); } else if qt.is_undoable_linked_var() && qt != st { - // e.g. Array(T, N) <: Add(Array(T, M)) - // Array((Int), (3)) <: Add(Array((Int), (4))): OK - // Array((Int), (3)) <: Add(Array((Str), (4))): NG + // e.g. List(T, N) <: Add(List(T, M)) + // List((Int), (3)) <: Add(List((Int), (4))): OK + // List((Int), (3)) <: Add(List((Str), (4))): NG if let Some(union) = self.ctx.unify(&qt, &st) { qt.undoable_link(&union, &self.undoable_linked); } else { @@ -331,7 +331,7 @@ impl<'c> Substituter<'c> { } // NOTE: Rarely, double overwriting occurs. // Whether this could be a problem is under consideration. - // e.g. `T` of Array(T, N) <: Add(T, M) + // e.g. `T` of List(T, N) <: Add(T, M) TyParam::FreeVar(ref fv) if fv.is_generalized() => { qtp.undoable_link(&stp, &self.undoable_linked); /*if let Err(errs) = self.sub_unify_tp(&stp, &qtp, None, &(), false) { @@ -785,23 +785,23 @@ impl Context { } } - pub(crate) fn eval_const_normal_array(&self, arr: &NormalArray) -> EvalResult { + pub(crate) fn eval_const_normal_list(&self, lis: &NormalList) -> EvalResult { let mut elems = vec![]; - for elem in arr.elems.pos_args().iter() { + for elem in lis.elems.pos_args().iter() { let elem = self.eval_const_expr(&elem.expr)?; elems.push(elem); } - Ok(ValueObj::Array(ArcArray::from(elems))) + Ok(ValueObj::List(ArcArray::from(elems))) } - fn eval_const_array(&self, arr: &Array) -> EvalResult { - match arr { - Array::Normal(arr) => self.eval_const_normal_array(arr), - Array::WithLength(arr) => { - let elem = self.eval_const_expr(&arr.elem.expr)?; - match arr.len.as_ref() { + fn eval_const_list(&self, lis: &List) -> EvalResult { + match lis { + List::Normal(lis) => self.eval_const_normal_list(lis), + List::WithLength(lis) => { + let elem = self.eval_const_expr(&lis.elem.expr)?; + match lis.len.as_ref() { Expr::Accessor(Accessor::Ident(ident)) if ident.is_discarded() => { - Ok(ValueObj::UnsizedArray(Box::new(elem))) + Ok(ValueObj::UnsizedList(Box::new(elem))) } other => { let len = self.eval_const_expr(other)?; @@ -820,14 +820,14 @@ impl Context { ) })?; let arr = vec![elem; len]; - Ok(ValueObj::Array(ArcArray::from(arr))) + Ok(ValueObj::List(ArcArray::from(arr))) } } } _ => Err(EvalErrors::from(EvalError::not_const_expr( self.cfg.input.clone(), line!() as usize, - arr.loc(), + lis.loc(), self.caused_by(), ))), } @@ -836,8 +836,8 @@ impl Context { fn eval_const_set(&self, set: &AstSet) -> EvalResult { let mut elems = vec![]; match set { - AstSet::Normal(arr) => { - for elem in arr.elems.pos_args().iter() { + AstSet::Normal(lis) => { + for elem in lis.elems.pos_args().iter() { let elem = self.eval_const_expr(&elem.expr)?; elems.push(elem); } @@ -875,8 +875,8 @@ impl Context { fn eval_const_tuple(&self, tuple: &Tuple) -> EvalResult { let mut elems = vec![]; match tuple { - Tuple::Normal(arr) => { - for elem in arr.elems.pos_args().iter() { + Tuple::Normal(lis) => { + for elem in lis.elems.pos_args().iter() { let elem = self.eval_const_expr(&elem.expr)?; elems.push(elem); } @@ -1109,7 +1109,7 @@ impl Context { Expr::BinOp(bin) => self.eval_const_bin(bin), Expr::UnaryOp(unary) => self.eval_const_unary(unary), Expr::Call(call) => self.eval_const_call(call), - Expr::Array(arr) => self.eval_const_array(arr), + Expr::List(lis) => self.eval_const_list(lis), Expr::Set(set) => self.eval_const_set(set), Expr::Dict(dict) => self.eval_const_dict(dict), Expr::Tuple(tuple) => self.eval_const_tuple(tuple), @@ -1139,7 +1139,7 @@ impl Context { Expr::BinOp(bin) => self.eval_const_bin(bin), Expr::UnaryOp(unary) => self.eval_const_unary(unary), Expr::Call(call) => self.eval_const_call(call), - Expr::Array(arr) => self.eval_const_array(arr), + Expr::List(lis) => self.eval_const_list(lis), Expr::Set(set) => self.eval_const_set(set), Expr::Dict(dict) => self.eval_const_dict(dict), Expr::Tuple(tuple) => self.eval_const_tuple(tuple), @@ -1412,8 +1412,8 @@ impl Context { (TyParam::Dict(l), TyParam::Dict(r)) if op == OpKind::Add => { Ok(TyParam::Dict(l.concat(r))) } - (TyParam::Array(l), TyParam::Array(r)) if op == OpKind::Add => { - Ok(TyParam::Array([l, r].concat())) + (TyParam::List(l), TyParam::List(r)) if op == OpKind::Add => { + Ok(TyParam::List([l, r].concat())) } (TyParam::FreeVar(fv), r) if fv.is_linked() => { let t = fv.crack().clone(); @@ -1563,16 +1563,16 @@ impl Context { TyParam::App { name, args } => self.eval_app(name, args), TyParam::BinOp { op, lhs, rhs } => self.eval_bin_tp(op, *lhs, *rhs), TyParam::UnaryOp { op, val } => self.eval_unary_tp(op, *val), - TyParam::Array(tps) => { + TyParam::List(tps) => { let mut new_tps = Vec::with_capacity(tps.len()); for tp in tps { new_tps.push(self.eval_tp(tp)?); } - Ok(TyParam::Array(new_tps)) + Ok(TyParam::List(new_tps)) } - TyParam::UnsizedArray(elem) => { + TyParam::UnsizedList(elem) => { let elem = self.eval_tp(*elem)?; - Ok(TyParam::UnsizedArray(Box::new(elem))) + Ok(TyParam::UnsizedList(Box::new(elem))) } TyParam::Tuple(tps) => { let mut new_tps = Vec::with_capacity(tps.len()); @@ -2055,17 +2055,17 @@ impl Context { } Ok(tuple_t(ts)) } - TyParam::Array(tps) => { + TyParam::List(tps) => { let mut union = Type::Never; let len = tps.len(); for tp in tps { union = self.union(&union, &self.convert_tp_into_type(tp)?); } - Ok(array_t(union, TyParam::value(len))) + Ok(list_t(union, TyParam::value(len))) } - TyParam::UnsizedArray(elem) => { + TyParam::UnsizedList(elem) => { let elem = self.convert_tp_into_type(*elem)?; - Ok(unknown_len_array_t(elem)) + Ok(unknown_len_list_t(elem)) } TyParam::Set(tps) => { let mut union = Type::Never; @@ -2095,7 +2095,7 @@ impl Context { let t = fv.crack().clone(); self.convert_tp_into_type(t) } - // TyParam(Ts: Array(Type)) -> Type(Ts: Array(Type)) + // TyParam(Ts: List(Type)) -> Type(Ts: List(Type)) // TyParam(?S(: Str)) -> Err(...), // TyParam(?D(: GenericDict)) -> Ok(?D(: GenericDict)), // FIXME: GenericDict @@ -2136,17 +2136,17 @@ impl Context { self.convert_tp_into_value(tp) } TyParam::Value(v) => Ok(v), - TyParam::Array(arr) => { + TyParam::List(lis) => { let mut new = vec![]; - for elem in arr { + for elem in lis { let elem = self.convert_tp_into_value(elem)?; new.push(elem); } - Ok(ValueObj::Array(new.into())) + Ok(ValueObj::List(new.into())) } - TyParam::UnsizedArray(elem) => { + TyParam::UnsizedList(elem) => { let elem = self.convert_tp_into_value(*elem)?; - Ok(ValueObj::UnsizedArray(Box::new(elem))) + Ok(ValueObj::UnsizedList(Box::new(elem))) } TyParam::Tuple(tys) => { let mut new = vec![]; @@ -2244,17 +2244,17 @@ impl Context { } Ok(tuple_t(new_ts)) } - ValueObj::Array(arr) => { - let len = TyParam::value(arr.len()); + ValueObj::List(lis) => { + let len = TyParam::value(lis.len()); let mut union = Type::Never; - for v in arr.iter().cloned() { + for v in lis.iter().cloned() { union = self.union(&union, &self.convert_value_into_type(v)?); } - Ok(array_t(union, len)) + Ok(list_t(union, len)) } - ValueObj::UnsizedArray(elem) => { + ValueObj::UnsizedList(elem) => { let elem = self.convert_value_into_type(*elem)?; - Ok(unknown_len_array_t(elem)) + Ok(unknown_len_list_t(elem)) } ValueObj::Set(set) => try_v_enum(set).map_err(ValueObj::Set), ValueObj::Dict(dic) => { @@ -2279,23 +2279,23 @@ impl Context { pub(crate) fn convert_value_into_tp(value: ValueObj) -> Result { match value { ValueObj::Type(t) => Ok(TyParam::t(t.into_typ())), - ValueObj::Array(arr) => { - let mut new_arr = vec![]; - for v in arr.iter().cloned() { + ValueObj::List(lis) => { + let mut new_lis = vec![]; + for v in lis.iter().cloned() { let tp = match Self::convert_value_into_tp(v) { Ok(tp) => tp, Err(tp) => tp, }; - new_arr.push(tp); + new_lis.push(tp); } - Ok(TyParam::Array(new_arr)) + Ok(TyParam::List(new_lis)) } - ValueObj::UnsizedArray(elem) => { + ValueObj::UnsizedList(elem) => { let tp = match Self::convert_value_into_tp(*elem) { Ok(tp) => tp, Err(tp) => tp, }; - Ok(TyParam::UnsizedArray(Box::new(tp))) + Ok(TyParam::UnsizedList(Box::new(tp))) } ValueObj::Tuple(vs) => { let mut new_ts = vec![]; @@ -2404,14 +2404,14 @@ impl Context { } } - pub(crate) fn convert_type_to_array(&self, ty: Type) -> Result, Type> { + pub(crate) fn convert_type_to_list(&self, ty: Type) -> Result, Type> { match ty { Type::FreeVar(fv) if fv.is_linked() => { let t = fv.crack().clone(); - self.convert_type_to_array(t) + self.convert_type_to_list(t) } - Type::Refinement(refine) => self.convert_type_to_array(*refine.t), - Type::Poly { name, params } if &name[..] == "Array" || &name[..] == "Array!" => { + Type::Refinement(refine) => self.convert_type_to_list(*refine.t), + Type::Poly { name, params } if &name[..] == "List" || &name[..] == "List!" => { let Ok(t) = self.convert_tp_into_type(params[0].clone()) else { log!(err "cannot convert to type: {}", params[0]); return Err(poly(name, params)); @@ -2429,14 +2429,11 @@ impl Context { } } - pub(crate) fn convert_value_into_array( - &self, - val: ValueObj, - ) -> Result, ValueObj> { + pub(crate) fn convert_value_into_list(&self, val: ValueObj) -> Result, ValueObj> { match val { - ValueObj::Array(arr) => Ok(arr.to_vec()), + ValueObj::List(lis) => Ok(lis.to_vec()), ValueObj::Type(t) => self - .convert_type_to_array(t.into_typ()) + .convert_type_to_list(t.into_typ()) .map_err(ValueObj::builtin_type), _ => Err(val), } @@ -2972,13 +2969,13 @@ impl Context { line!(), )) }), - TyParam::Array(tps) => { + TyParam::List(tps) => { let tp_t = if let Some(fst) = tps.first() { self.get_tp_t(fst)? } else { Never }; - let t = array_t(tp_t, TyParam::value(tps.len())); + let t = list_t(tp_t, TyParam::value(tps.len())); Ok(t) } TyParam::Tuple(tps) => { @@ -3113,7 +3110,7 @@ impl Context { (TyParam::Type(l), TyParam::Type(r)) => l == r, (TyParam::Value(l), TyParam::Value(r)) => l == r, (TyParam::Erased(l), TyParam::Erased(r)) => l == r, - (TyParam::Array(l), TyParam::Array(r)) => l == r, + (TyParam::List(l), TyParam::List(r)) => l == r, (TyParam::Tuple(l), TyParam::Tuple(r)) => l == r, (TyParam::Set(l), TyParam::Set(r)) => l == r, // FIXME: (TyParam::Dict(l), TyParam::Dict(r)) => l == r, diff --git a/crates/erg_compiler/context/generalize.rs b/crates/erg_compiler/context/generalize.rs index ebd518c3c..547d19c57 100644 --- a/crates/erg_compiler/context/generalize.rs +++ b/crates/erg_compiler/context/generalize.rs @@ -59,7 +59,7 @@ impl Generalizer { fv.generalize(); TyParam::FreeVar(fv) } - TyParam::Array(tps) => TyParam::Array( + TyParam::List(tps) => TyParam::List( tps.into_iter() .map(|tp| self.generalize_tp(tp, uninit)) .collect(), @@ -496,12 +496,12 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> { val: Box::new(val), }) } - TyParam::Array(tps) => { + TyParam::List(tps) => { let mut new_tps = vec![]; for tp in tps { new_tps.push(self.deref_tp(tp)?); } - Ok(TyParam::Array(new_tps)) + Ok(TyParam::List(new_tps)) } TyParam::Tuple(tps) => { let mut new_tps = vec![]; @@ -1374,24 +1374,24 @@ impl Context { } Ok(()) } - hir::Expr::Array(array) => match array { - hir::Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter_mut() { + hir::Expr::List(list) => match list { + hir::List::Normal(lis) => { + for elem in lis.elems.pos_args.iter_mut() { self.resolve_expr_t(&mut elem.expr, qnames)?; } - let t = mem::take(&mut arr.t); - let mut dereferencer = Dereferencer::simple(self, qnames, arr); - arr.t = dereferencer.deref_tyvar(t)?; + let t = mem::take(&mut lis.t); + let mut dereferencer = Dereferencer::simple(self, qnames, lis); + lis.t = dereferencer.deref_tyvar(t)?; Ok(()) } - hir::Array::WithLength(arr) => { - self.resolve_expr_t(&mut arr.elem, qnames)?; - if let Some(len) = &mut arr.len { + hir::List::WithLength(lis) => { + self.resolve_expr_t(&mut lis.elem, qnames)?; + if let Some(len) = &mut lis.len { self.resolve_expr_t(len, qnames)?; } - let t = mem::take(&mut arr.t); - let mut dereferencer = Dereferencer::simple(self, qnames, arr); - arr.t = dereferencer.deref_tyvar(t)?; + let t = mem::take(&mut lis.t); + let mut dereferencer = Dereferencer::simple(self, qnames, lis); + lis.t = dereferencer.deref_tyvar(t)?; Ok(()) } other => feature_error!( diff --git a/crates/erg_compiler/context/hint.rs b/crates/erg_compiler/context/hint.rs index 88121f8c4..e7826d022 100644 --- a/crates/erg_compiler/context/hint.rs +++ b/crates/erg_compiler/context/hint.rs @@ -44,7 +44,7 @@ impl Context { expected: &Type, found: &Type, ) -> Option { - if &callee_t.qual_name()[..] == "Array" && attr == Some("__getitem__") && nth == 1 { + if &callee_t.qual_name()[..] == "List" && attr == Some("__getitem__") && nth == 1 { let len = &callee_t.typarams().get(1).cloned()?; let (_, _, pred) = found.clone().deconstruct_refinement().ok()?; if let Predicate::Equal { rhs: accessed, .. } = pred { @@ -58,10 +58,10 @@ impl Context { accessed.clone() }; return Some(switch_lang! { - "japanese" => format!("配列の長さは{len}ですが、{accessed}番目の要素にアクセスしようとしています"), + "japanese" => format!("リストの長さは{len}ですが、{accessed}番目の要素にアクセスしようとしています"), "simplified_chinese" => format!("数组长度为{len}但尝试访问第{accessed}个元素"), "traditional_chinese" => format!("陣列長度為{len}但嘗試訪問第{accessed}個元素"), - "english" => format!("Array length is {len} but tried to access the {accessed}th element"), + "english" => format!("List length is {len} but tried to access the {accessed}th element"), }); } } diff --git a/crates/erg_compiler/context/initialize/classes.rs b/crates/erg_compiler/context/initialize/classes.rs index 6e6023ced..dfd4009c0 100644 --- a/crates/erg_compiler/context/initialize/classes.rs +++ b/crates/erg_compiler/context/initialize/classes.rs @@ -489,7 +489,7 @@ impl Context { BYTES, or( mono(BYTES), - array_t(Type::from(value(0)..=value(255)), TyParam::erased(Nat)), + list_t(Type::from(value(0)..=value(255)), TyParam::erased(Nat)), ), )], vec![kw( @@ -954,7 +954,7 @@ impl Context { None, vec![kw(KW_MAXSPLIT, Nat)], None, - unknown_len_array_t(Str), + unknown_len_list_t(Str), ), Immutable, Visibility::BUILTIN_PUBLIC, @@ -968,7 +968,7 @@ impl Context { None, vec![kw(KW_KEEPENDS, Bool)], None, - unknown_len_array_t(Str), + unknown_len_list_t(Str), ), Immutable, Visibility::BUILTIN_PUBLIC, @@ -1356,14 +1356,14 @@ impl Context { type_.register_superclass(Obj, &obj); type_.register_builtin_erg_impl( FUNC_MRO, - fn0_met(Type, array_t(Type, TyParam::erased(Nat))), + fn0_met(Type, list_t(Type, TyParam::erased(Nat))), Immutable, Visibility::BUILTIN_PUBLIC, ); // TODO: PolyType type_.register_builtin_erg_impl( FUNDAMENTAL_ARGS, - array_t(Type, TyParam::erased(Nat)), + list_t(Type, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); @@ -1424,31 +1424,31 @@ impl Context { ); code.register_builtin_erg_impl( FUNC_CO_VARNAMES, - array_t(Str, TyParam::erased(Nat)), + list_t(Str, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); code.register_builtin_erg_impl( FUNC_CO_CONSTS, - array_t(Obj, TyParam::erased(Nat)), + list_t(Obj, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); code.register_builtin_erg_impl( FUNC_CO_NAMES, - array_t(Str, TyParam::erased(Nat)), + list_t(Str, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); code.register_builtin_erg_impl( FUNC_CO_FREEVARS, - array_t(Str, TyParam::erased(Nat)), + list_t(Str, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); code.register_builtin_erg_impl( FUNC_CO_CELLVARS, - array_t(Str, TyParam::erased(Nat)), + list_t(Str, TyParam::erased(Nat)), Immutable, Visibility::BUILTIN_PUBLIC, ); @@ -1566,100 +1566,100 @@ impl Context { if ERG_MODE { py_module.register_superclass(g_module_t.clone(), &generic_module); } - /* GenericArray */ - let mut generic_array = Self::builtin_mono_class(GENERIC_ARRAY, 1); - generic_array.register_superclass(Obj, &obj); + /* GenericList */ + let mut generic_list = Self::builtin_mono_class(GENERIC_LIST, 1); + generic_list.register_superclass(Obj, &obj); let mut arr_eq = Self::builtin_methods(Some(mono(EQ)), 2); arr_eq.register_builtin_erg_impl( OP_EQ, - fn1_met(mono(GENERIC_ARRAY), mono(GENERIC_ARRAY), Bool), + fn1_met(mono(GENERIC_LIST), mono(GENERIC_LIST), Bool), Const, Visibility::BUILTIN_PUBLIC, ); - generic_array.register_trait_methods(mono(GENERIC_ARRAY), arr_eq); + generic_list.register_trait_methods(mono(GENERIC_LIST), arr_eq); let t_call = func1( poly(ITERABLE, vec![ty_tp(T.clone())]), - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ) .quantify(); - generic_array.register_builtin_erg_impl( + generic_list.register_builtin_erg_impl( FUNDAMENTAL_CALL, t_call, Immutable, Visibility::BUILTIN_PUBLIC, ); - let mut array_hash = Self::builtin_methods(Some(mono(HASH)), 1); - array_hash.register_builtin_erg_impl( + let mut list_hash = Self::builtin_methods(Some(mono(HASH)), 1); + list_hash.register_builtin_erg_impl( OP_HASH, - fn0_met(mono(GENERIC_ARRAY), Int), + fn0_met(mono(GENERIC_LIST), Int), Const, Visibility::BUILTIN_PUBLIC, ); - generic_array.register_trait_methods(mono(GENERIC_ARRAY), array_hash); - let unsized_array_t = poly(UNSIZED_ARRAY, vec![ty_tp(T.clone())]); - let mut unsized_array = - Self::builtin_poly_class(UNSIZED_ARRAY, vec![ParamSpec::t_nd(TY_T)], 1); - unsized_array.register_superclass(Obj, &obj); - unsized_array.register_builtin_decl(KW_ELEM, T.clone(), vis.clone(), Some(KW_ELEM)); - /* Array */ - let mut array_ = - Self::builtin_poly_class(ARRAY, vec![PS::t_nd(TY_T), PS::default(TY_N, Nat)], 10); - array_.register_superclass(mono(GENERIC_ARRAY), &generic_array); - array_ + generic_list.register_trait_methods(mono(GENERIC_LIST), list_hash); + let unsized_list_t = poly(UNSIZED_LIST, vec![ty_tp(T.clone())]); + let mut unsized_list = + Self::builtin_poly_class(UNSIZED_LIST, vec![ParamSpec::t_nd(TY_T)], 1); + unsized_list.register_superclass(Obj, &obj); + unsized_list.register_builtin_decl(KW_ELEM, T.clone(), vis.clone(), Some(KW_ELEM)); + /* List */ + let mut list_ = + Self::builtin_poly_class(LIST, vec![PS::t_nd(TY_T), PS::default(TY_N, Nat)], 10); + list_.register_superclass(mono(GENERIC_LIST), &generic_list); + list_ .register_trait(self, poly(OUTPUT, vec![ty_tp(T.clone())])) .unwrap(); - let arr_t = array_t(T.clone(), N.clone()); + let lis_t = list_t(T.clone(), N.clone()); let t = no_var_fn_met( - arr_t.clone(), - vec![kw(KW_RHS, array_t(T.clone(), M.clone()))], + lis_t.clone(), + vec![kw(KW_RHS, list_t(T.clone(), M.clone()))], vec![], - array_t(T.clone(), N.clone() + M.clone()), + list_t(T.clone(), N.clone() + M.clone()), ) .quantify(); - array_.register_py_builtin(FUNC_CONCAT, t.clone(), Some(OP_ADD), 9); + list_.register_py_builtin(FUNC_CONCAT, t.clone(), Some(OP_ADD), 9); let t_count = - no_var_fn_met(arr_t.clone(), vec![kw(KW_X, T.clone())], vec![], Nat).quantify(); - array_.register_py_builtin(FUNC_COUNT, t_count, Some(FUNC_COUNT), 17); + no_var_fn_met(lis_t.clone(), vec![kw(KW_X, T.clone())], vec![], Nat).quantify(); + list_.register_py_builtin(FUNC_COUNT, t_count, Some(FUNC_COUNT), 17); let t_get = no_var_fn_met( - arr_t.clone(), + lis_t.clone(), vec![pos(Nat)], vec![ParamTy::kw_default(KW_DEFAULT.into(), U.clone(), NoneType)], or(T.clone(), U.clone()), ) .quantify(); - array_.register_builtin_erg_impl(FUNC_GET, t_get, Immutable, Visibility::BUILTIN_PUBLIC); - // Array(T, N)|<: Add(Array(T, M))|. - // Output = Array(T, N + M) - // __add__: (self: Array(T, N), other: Array(T, M)) -> Array(T, N + M) = Array.concat - let mut array_add = Self::builtin_methods( - Some(poly(ADD, vec![ty_tp(array_t(T.clone(), M.clone()))])), + list_.register_builtin_erg_impl(FUNC_GET, t_get, Immutable, Visibility::BUILTIN_PUBLIC); + // List(T, N)|<: Add(List(T, M))|. + // Output = List(T, N + M) + // __add__: (self: List(T, N), other: List(T, M)) -> List(T, N + M) = List.concat + let mut list_add = Self::builtin_methods( + Some(poly(ADD, vec![ty_tp(list_t(T.clone(), M.clone()))])), 2, ); - array_add.register_builtin_erg_impl(OP_ADD, t, Immutable, Visibility::BUILTIN_PUBLIC); - let out_t = array_t(T.clone(), N.clone() + M.clone()); - array_add.register_builtin_const( + list_add.register_builtin_erg_impl(OP_ADD, t, Immutable, Visibility::BUILTIN_PUBLIC); + let out_t = list_t(T.clone(), N.clone() + M.clone()); + list_add.register_builtin_const( OUTPUT, Visibility::BUILTIN_PUBLIC, None, ValueObj::builtin_class(out_t), ); - array_.register_trait_methods(arr_t.clone(), array_add); + list_.register_trait_methods(lis_t.clone(), list_add); let t = no_var_fn_met( - arr_t.clone(), + lis_t.clone(), vec![kw(KW_ELEM, T.clone())], vec![], - array_t(T.clone(), N.clone() + value(1usize)), + list_t(T.clone(), N.clone() + value(1usize)), ) .quantify(); - array_.register_builtin_erg_impl(FUNC_PUSH, t, Immutable, Visibility::BUILTIN_PUBLIC); + list_.register_builtin_erg_impl(FUNC_PUSH, t, Immutable, Visibility::BUILTIN_PUBLIC); let repeat_t = no_var_fn_met( - arr_t.clone(), + lis_t.clone(), vec![pos(singleton(Nat, M.clone()))], vec![], - array_t(T.clone(), N.clone() * M.clone()), + list_t(T.clone(), N.clone() * M.clone()), ) .quantify(); - array_.register_builtin_erg_impl( + list_.register_builtin_erg_impl( FUNC_REPEAT, repeat_t, Immutable, @@ -1667,15 +1667,15 @@ impl Context { ); // [T; N].MutType! = [T; !N] (neither [T!; N] nor [T; N]!) let mut_type = - ValueObj::builtin_class(poly(MUT_ARRAY, vec![TyParam::t(T.clone()), N.clone()])); - let mut array_mutizable = Self::builtin_methods(Some(mono(MUTIZABLE)), 2); - array_mutizable.register_builtin_const( + ValueObj::builtin_class(poly(MUT_LIST, vec![TyParam::t(T.clone()), N.clone()])); + let mut list_mutizable = Self::builtin_methods(Some(mono(MUTIZABLE)), 2); + list_mutizable.register_builtin_const( MUTABLE_MUT_TYPE, Visibility::BUILTIN_PUBLIC, None, mut_type, ); - array_.register_trait_methods(arr_t.clone(), array_mutizable); + list_.register_trait_methods(lis_t.clone(), list_mutizable); let var = FRESH_GEN.fresh_varname(); let input = refinement( var.clone(), @@ -1684,259 +1684,254 @@ impl Context { ); // __getitem__: |T, N|(self: [T; N], _: {I: Nat | I <= N}) -> T // and (self: [T; N], _: Range(Int)) -> [T; _] - let array_getitem_t = (fn1_kw_met( - array_t(T.clone(), N.clone()), - anon(input.clone()), - T.clone(), - ) & fn1_kw_met( - array_t(T.clone(), N.clone()), - anon(poly(RANGE, vec![ty_tp(Int)])), - unknown_len_array_t(T.clone()), - )) - .quantify(); + let list_getitem_t = + (fn1_kw_met(list_t(T.clone(), N.clone()), anon(input.clone()), T.clone()) + & fn1_kw_met( + list_t(T.clone(), N.clone()), + anon(poly(RANGE, vec![ty_tp(Int)])), + unknown_len_list_t(T.clone()), + )) + .quantify(); let get_item = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNDAMENTAL_GETITEM, - __array_getitem__, - array_getitem_t, + __list_getitem__, + list_getitem_t, None, ))); - array_.register_builtin_const( + list_.register_builtin_const( FUNDAMENTAL_GETITEM, Visibility::BUILTIN_PUBLIC, None, get_item, ); - let array_insert_t = no_var_fn_met( - array_t(T.clone(), N.clone()), + let list_insert_t = no_var_fn_met( + list_t(T.clone(), N.clone()), vec![pos(Nat), kw(KW_ELEM, T.clone())], vec![], - array_t(T.clone(), N.clone() + value(1usize)), + list_t(T.clone(), N.clone() + value(1usize)), ) .quantify(); - let array_insert = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( + let list_insert = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_INSERT, - array_insert_at, - array_insert_t.clone(), + list_insert_at, + list_insert_t.clone(), None, ))); - array_._register_builtin_const( + list_._register_builtin_const( FUNC_INSERT, Visibility::BUILTIN_PUBLIC, - Some(array_insert_t), - array_insert, + Some(list_insert_t), + list_insert, Some(FUNC_INSERT_AT.into()), ); - let array_remove_at_t = no_var_fn_met( - array_t(T.clone(), N.clone()), + let list_remove_at_t = no_var_fn_met( + list_t(T.clone(), N.clone()), vec![pos(Nat)], vec![], - array_t(T.clone(), N.clone() - value(1usize)), + list_t(T.clone(), N.clone() - value(1usize)), ) .quantify(); - let array_remove_at = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( + let list_remove_at = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_REMOVE_AT, - array_remove_at, - array_remove_at_t.clone(), + list_remove_at, + list_remove_at_t.clone(), None, ))); - array_.register_builtin_const( + list_.register_builtin_const( FUNC_REMOVE_AT, Visibility::BUILTIN_PUBLIC, - Some(array_remove_at_t), - array_remove_at, + Some(list_remove_at_t), + list_remove_at, ); - let array_remove_all_t = no_var_fn_met( - array_t(T.clone(), N.clone()), + let list_remove_all_t = no_var_fn_met( + list_t(T.clone(), N.clone()), vec![kw(KW_ELEM, T.clone())], vec![], - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ) .quantify(); - let array_remove_all = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( + let list_remove_all = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_REMOVE_ALL, - array_remove_all, - array_remove_all_t.clone(), + list_remove_all, + list_remove_all_t.clone(), None, ))); - array_.register_builtin_const( + list_.register_builtin_const( FUNC_REMOVE_ALL, Visibility::BUILTIN_PUBLIC, - Some(array_remove_all_t), - array_remove_all, + Some(list_remove_all_t), + list_remove_all, ); - array_ + list_ .register_trait(self, poly(INDEXABLE, vec![ty_tp(input), ty_tp(T.clone())])) .unwrap(); - array_ + list_ .register_trait( self, poly( HAS_SHAPE, - vec![ty_tp(arr_t.clone()).proj_call(FUNC_SHAPE.into(), vec![])], + vec![ty_tp(lis_t.clone()).proj_call(FUNC_SHAPE.into(), vec![])], ), ) .unwrap(); - array_ + list_ .register_trait( self, poly( HAS_SCALAR_TYPE, - vec![ty_tp(arr_t.clone()).proj_call(FUNC_SCALAR_TYPE.into(), vec![])], + vec![ty_tp(lis_t.clone()).proj_call(FUNC_SCALAR_TYPE.into(), vec![])], ), ) .unwrap(); - let mut array_sized = Self::builtin_methods(Some(mono(SIZED)), 2); - array_sized.register_builtin_erg_impl( + let mut list_sized = Self::builtin_methods(Some(mono(SIZED)), 2); + list_sized.register_builtin_erg_impl( FUNDAMENTAL_LEN, - fn0_met(arr_t.clone(), Nat).quantify(), + fn0_met(lis_t.clone(), Nat).quantify(), Const, Visibility::BUILTIN_PUBLIC, ); - array_.register_trait_methods(arr_t.clone(), array_sized); + list_.register_trait_methods(lis_t.clone(), list_sized); // union: (self: [Type; _]) -> Type - let array_union_t = fn0_met(array_t(Type, TyParam::erased(Nat)), Type).quantify(); + let list_union_t = fn0_met(list_t(Type, TyParam::erased(Nat)), Type).quantify(); let union = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_UNION, - array_union, - array_union_t, + list_union, + list_union_t, None, ))); - array_.register_builtin_const(FUNC_UNION, Visibility::BUILTIN_PUBLIC, None, union); + list_.register_builtin_const(FUNC_UNION, Visibility::BUILTIN_PUBLIC, None, union); // shape: (self: [Type; _]) -> [Nat; _] - let array_shape_t = fn0_met( - array_t(Type, TyParam::erased(Nat)), - unknown_len_array_t(Nat), - ) - .quantify(); + let list_shape_t = + fn0_met(list_t(Type, TyParam::erased(Nat)), unknown_len_list_t(Nat)).quantify(); let shape = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_SHAPE, - array_shape, - array_shape_t, + list_shape, + list_shape_t, None, ))); - array_.register_builtin_const(FUNC_SHAPE, Visibility::BUILTIN_PUBLIC, None, shape); - let array_scalar_type_t = fn0_met(Type, Type).quantify(); - let array_scalar_type = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( + list_.register_builtin_const(FUNC_SHAPE, Visibility::BUILTIN_PUBLIC, None, shape); + let list_scalar_type_t = fn0_met(Type, Type).quantify(); + let list_scalar_type = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_SCALAR_TYPE, - array_scalar_type, - array_scalar_type_t, + list_scalar_type, + list_scalar_type_t, None, ))); - array_.register_builtin_const( + list_.register_builtin_const( FUNC_SCALAR_TYPE, Visibility::BUILTIN_PUBLIC, None, - array_scalar_type, + list_scalar_type, ); - let mut array_eq = Self::builtin_methods(Some(mono(EQ)), 2); - array_eq.register_builtin_erg_impl( + let mut list_eq = Self::builtin_methods(Some(mono(EQ)), 2); + list_eq.register_builtin_erg_impl( OP_EQ, - fn1_met(arr_t.clone(), arr_t.clone(), Bool).quantify(), + fn1_met(lis_t.clone(), lis_t.clone(), Bool).quantify(), Const, Visibility::BUILTIN_PUBLIC, ); - array_.register_trait_methods(arr_t.clone(), array_eq); - array_ + list_.register_trait_methods(lis_t.clone(), list_eq); + list_ .register_trait(self, poly(SEQUENCE, vec![ty_tp(T.clone())])) .unwrap(); - array_.unregister_trait(&poly(INDEXABLE, vec![ty_tp(Nat), ty_tp(T.clone())])); - let mut array_show = Self::builtin_methods(Some(mono(SHOW)), 1); - array_show.register_builtin_py_impl( + list_.unregister_trait(&poly(INDEXABLE, vec![ty_tp(Nat), ty_tp(T.clone())])); + let mut list_show = Self::builtin_methods(Some(mono(SHOW)), 1); + list_show.register_builtin_py_impl( FUNDAMENTAL_STR, - fn0_met(arr_t.clone(), Str).quantify(), + fn0_met(lis_t.clone(), Str).quantify(), Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNDAMENTAL_STR), ); - array_.register_trait_methods(arr_t.clone(), array_show); - let mut array_iterable = + list_.register_trait_methods(lis_t.clone(), list_show); + let mut list_iterable = Self::builtin_methods(Some(poly(ITERABLE, vec![ty_tp(T.clone())])), 2); - let array_iter = poly(ARRAY_ITERATOR, vec![ty_tp(T.clone())]); - let t = fn0_met(array_t(T.clone(), TyParam::erased(Nat)), array_iter.clone()).quantify(); - array_iterable.register_builtin_py_impl( + let list_iter = poly(LIST_ITERATOR, vec![ty_tp(T.clone())]); + let t = fn0_met(list_t(T.clone(), TyParam::erased(Nat)), list_iter.clone()).quantify(); + list_iterable.register_builtin_py_impl( FUNC_ITER, t, Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNDAMENTAL_ITER), ); - array_iterable.register_builtin_const( + list_iterable.register_builtin_const( ITERATOR, vis.clone(), None, - ValueObj::builtin_class(array_iter), + ValueObj::builtin_class(list_iter), ); - array_.register_trait_methods(arr_t.clone(), array_iterable); - let mut array_collection = + list_.register_trait_methods(lis_t.clone(), list_iterable); + let mut list_collection = Self::builtin_methods(Some(poly(COLLECTION, vec![ty_tp(T.clone())])), 4); - array_collection.register_builtin_erg_impl( + list_collection.register_builtin_erg_impl( FUNDAMENTAL_CONTAINS, - fn1_met(arr_t.clone(), T.clone(), Bool).quantify(), + fn1_met(lis_t.clone(), T.clone(), Bool).quantify(), Const, Visibility::BUILTIN_PUBLIC, ); - array_.register_trait_methods(arr_t.clone(), array_collection); - array_ + list_.register_trait_methods(lis_t.clone(), list_collection); + list_ .register_trait(self, poly(COLLECTION, vec![ty_tp(T.clone())])) .unwrap(); let t = fn1_met( - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), func1(T.clone(), Bool), tuple_t(vec![ - array_t(T.clone(), TyParam::erased(Nat)), - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ]), ); - array_.register_py_builtin(FUNC_PARTITION, t.quantify(), Some(FUNC_PARTITION), 37); + list_.register_py_builtin(FUNC_PARTITION, t.quantify(), Some(FUNC_PARTITION), 37); let t = no_var_fn_met( - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), vec![], vec![kw( KW_SAME_BUCKET, or(func2(T.clone(), T.clone(), Bool), NoneType), )], - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ); - array_.register_py_builtin(FUNC_DEDUP, t.quantify(), Some(FUNC_DEDUP), 28); + list_.register_py_builtin(FUNC_DEDUP, t.quantify(), Some(FUNC_DEDUP), 28); let sum_t = no_var_fn_met( - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), vec![], vec![kw(KW_START, T.clone())], T.clone(), ); let sum = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_SUM, - array_sum, + list_sum, sum_t.quantify(), None, ))); - array_.register_builtin_const(FUNC_SUM, Visibility::BUILTIN_PUBLIC, None, sum); + list_.register_builtin_const(FUNC_SUM, Visibility::BUILTIN_PUBLIC, None, sum); let prod_t = no_var_fn_met( - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), vec![], vec![kw(KW_START, T.clone())], T.clone(), ); let prod = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_PROD, - array_prod, + list_prod, prod_t.quantify(), None, ))); - array_.register_builtin_const(FUNC_PROD, Visibility::BUILTIN_PUBLIC, None, prod); + list_.register_builtin_const(FUNC_PROD, Visibility::BUILTIN_PUBLIC, None, prod); let reversed_t = no_var_fn_met( - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), vec![], vec![], - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ); let reversed = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new( FUNC_REVERSED, - array_reversed, + list_reversed, reversed_t.quantify(), None, ))); - array_.register_builtin_const(FUNC_REVERSED, Visibility::BUILTIN_PUBLIC, None, reversed); + list_.register_builtin_const(FUNC_REVERSED, Visibility::BUILTIN_PUBLIC, None, reversed); /* Slice */ let mut slice = Self::builtin_mono_class(SLICE, 3); slice.register_superclass(Obj, &obj); @@ -2284,7 +2279,7 @@ impl Context { /* GenericTuple */ let mut generic_tuple = Self::builtin_mono_class(GENERIC_TUPLE, 1); generic_tuple.register_superclass(Obj, &obj); - // tuple doesn't have a constructor, use `Array` instead + // tuple doesn't have a constructor, use `List` instead let mut tuple_eq = Self::builtin_methods(Some(mono(EQ)), 2); tuple_eq.register_builtin_erg_impl( OP_EQ, @@ -2302,14 +2297,11 @@ impl Context { ); generic_tuple.register_trait_methods(mono(GENERIC_TUPLE), tuple_hash); generic_tuple.register_trait(self, mono(EQ_HASH)).unwrap(); - let Ts = mono_q_tp(TY_TS, instanceof(array_t(Type, N.clone()))); - // Ts <: GenericArray + let Ts = mono_q_tp(TY_TS, instanceof(list_t(Type, N.clone()))); + // Ts <: GenericList let _tuple_t = poly(TUPLE, vec![Ts.clone()]); - let mut tuple_ = Self::builtin_poly_class( - TUPLE, - vec![PS::named_nd(TY_TS, array_t(Type, N.clone()))], - 2, - ); + let mut tuple_ = + Self::builtin_poly_class(TUPLE, vec![PS::named_nd(TY_TS, list_t(Type, N.clone()))], 2); tuple_.register_superclass(mono(GENERIC_TUPLE), &generic_tuple); tuple_ .register_trait(self, poly(OUTPUT, vec![Ts.clone()])) @@ -2498,12 +2490,12 @@ impl Context { str_iterator .register_trait(self, poly(OUTPUT, vec![ty_tp(Str)])) .unwrap(); - let mut array_iterator = Self::builtin_poly_class(ARRAY_ITERATOR, vec![PS::t_nd(TY_T)], 1); - array_iterator.register_superclass(Obj, &obj); - array_iterator + let mut list_iterator = Self::builtin_poly_class(LIST_ITERATOR, vec![PS::t_nd(TY_T)], 1); + list_iterator.register_superclass(Obj, &obj); + list_iterator .register_trait(self, poly(ITERABLE, vec![ty_tp(T.clone())])) .unwrap(); - array_iterator + list_iterator .register_trait(self, poly(OUTPUT, vec![ty_tp(T.clone())])) .unwrap(); let mut set_iterator = Self::builtin_poly_class(SET_ITERATOR, vec![PS::t_nd(TY_T)], 1); @@ -3004,16 +2996,16 @@ impl Context { file_mut .register_trait(self, mono(CONTEXT_MANAGER)) .unwrap(); - /* Array! */ - let array_mut_t = poly(MUT_ARRAY, vec![ty_tp(T.clone()), N.clone()]); - let mut array_mut_ = - Self::builtin_poly_class(MUT_ARRAY, vec![PS::t_nd(TY_T), PS::default(TY_N, Nat)], 2); - array_mut_.register_superclass(arr_t.clone(), &array_); + /* List! */ + let list_mut_t = poly(MUT_LIST, vec![ty_tp(T.clone()), N.clone()]); + let mut list_mut_ = + Self::builtin_poly_class(MUT_LIST, vec![PS::t_nd(TY_T), PS::default(TY_N, Nat)], 2); + list_mut_.register_superclass(lis_t.clone(), &list_); let t = pr_met( ref_mut( - array_mut_t.clone(), + list_mut_t.clone(), Some(poly( - MUT_ARRAY, + MUT_LIST, vec![ty_tp(T.clone()), N.clone() + value(1usize)], )), ), @@ -3023,18 +3015,15 @@ impl Context { NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_PUSH, t, Some(FUNC_APPEND), 15); - let t_copy = fn0_met(ref_(array_mut_t.clone()), array_mut_t.clone()).quantify(); - let mut array_mut_copy = Self::builtin_methods(Some(mono(COPY)), 2); - array_mut_copy.register_py_builtin(FUNC_COPY, t_copy, Some(FUNC_COPY), 116); - array_mut_.register_trait_methods(array_mut_t.clone(), array_mut_copy); + list_mut_.register_py_builtin(PROC_PUSH, t, Some(FUNC_APPEND), 15); + let t_copy = fn0_met(ref_(list_mut_t.clone()), list_mut_t.clone()).quantify(); + let mut list_mut_copy = Self::builtin_methods(Some(mono(COPY)), 2); + list_mut_copy.register_py_builtin(FUNC_COPY, t_copy, Some(FUNC_COPY), 116); + list_mut_.register_trait_methods(list_mut_t.clone(), list_mut_copy); let t_extend = pr_met( ref_mut( - array_mut_t.clone(), - Some(poly( - MUT_ARRAY, - vec![ty_tp(T.clone()), TyParam::erased(Nat)], - )), + list_mut_t.clone(), + Some(poly(MUT_LIST, vec![ty_tp(T.clone()), TyParam::erased(Nat)])), ), vec![kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())]))], None, @@ -3042,12 +3031,12 @@ impl Context { NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_EXTEND, t_extend, Some(FUNC_EXTEND), 24); + list_mut_.register_py_builtin(PROC_EXTEND, t_extend, Some(FUNC_EXTEND), 24); let t_insert = pr_met( ref_mut( - array_mut_t.clone(), + list_mut_t.clone(), Some(poly( - MUT_ARRAY, + MUT_LIST, vec![ty_tp(T.clone()), N.clone() + value(1usize)], )), ), @@ -3057,12 +3046,12 @@ impl Context { NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_INSERT, t_insert, Some(FUNC_INSERT), 33); + list_mut_.register_py_builtin(PROC_INSERT, t_insert, Some(FUNC_INSERT), 33); let t_remove = pr_met( ref_mut( - array_mut_t.clone(), + list_mut_t.clone(), Some(poly( - MUT_ARRAY, + MUT_LIST, vec![ty_tp(T.clone()), N.clone() - value(1usize)], )), ), @@ -3072,12 +3061,12 @@ impl Context { NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_REMOVE, t_remove, Some(FUNC_REMOVE), 42); + list_mut_.register_py_builtin(PROC_REMOVE, t_remove, Some(FUNC_REMOVE), 42); let t_pop = pr_met( ref_mut( - array_mut_t.clone(), + list_mut_t.clone(), Some(poly( - MUT_ARRAY, + MUT_LIST, vec![ty_tp(T.clone()), N.clone() - value(1usize)], )), ), @@ -3087,18 +3076,18 @@ impl Context { T.clone(), ) .quantify(); - array_mut_.register_py_builtin(PROC_POP, t_pop, Some(FUNC_POP), 52); + list_mut_.register_py_builtin(PROC_POP, t_pop, Some(FUNC_POP), 52); let t_clear = pr0_met( ref_mut( - array_mut_t.clone(), - Some(poly(MUT_ARRAY, vec![ty_tp(T.clone()), value(0usize)])), + list_mut_t.clone(), + Some(poly(MUT_LIST, vec![ty_tp(T.clone()), value(0usize)])), ), NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_CLEAR, t_clear, Some(FUNC_CLEAR), 61); + list_mut_.register_py_builtin(PROC_CLEAR, t_clear, Some(FUNC_CLEAR), 61); let t_sort = pr_met( - ref_mut(array_mut_t.clone(), None), + ref_mut(list_mut_t.clone(), None), vec![], None, vec![kw( @@ -3108,77 +3097,77 @@ impl Context { NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_SORT, t_sort, Some(FUNC_SORT), 78); - let t_reverse = pr0_met(ref_mut(array_mut_t.clone(), None), NoneType).quantify(); - array_mut_.register_py_builtin(PROC_REVERSE, t_reverse, Some(FUNC_REVERSE), 87); + list_mut_.register_py_builtin(PROC_SORT, t_sort, Some(FUNC_SORT), 78); + let t_reverse = pr0_met(ref_mut(list_mut_t.clone(), None), NoneType).quantify(); + list_mut_.register_py_builtin(PROC_REVERSE, t_reverse, Some(FUNC_REVERSE), 87); let t = pr_met( - array_mut_t.clone(), + list_mut_t.clone(), vec![kw(KW_FUNC, nd_func(vec![anon(T.clone())], None, T.clone()))], None, vec![], NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_STRICT_MAP, t, None, 96); + list_mut_.register_py_builtin(PROC_STRICT_MAP, t, None, 96); let t_update_nth = pr_met( - ref_mut(array_mut_t.clone(), None), + ref_mut(list_mut_t.clone(), None), vec![kw(KW_IDX, Nat), kw(KW_FUNC, func1(T.clone(), T.clone()))], None, vec![], NoneType, ) .quantify(); - array_mut_.register_py_builtin(PROC_UPDATE_NTH, t_update_nth, Some(FUNC_UPDATE_NTH), 105); + list_mut_.register_py_builtin(PROC_UPDATE_NTH, t_update_nth, Some(FUNC_UPDATE_NTH), 105); let f_t = kw( KW_FUNC, - no_var_func(vec![kw(KW_OLD, arr_t.clone())], vec![], arr_t.clone()), + no_var_func(vec![kw(KW_OLD, lis_t.clone())], vec![], lis_t.clone()), ); let t = pr_met( - ref_mut(array_mut_t.clone(), None), + ref_mut(list_mut_t.clone(), None), vec![f_t], None, vec![], NoneType, ) .quantify(); - let mut array_mut_mutable = Self::builtin_methods(Some(mono(MUTABLE)), 2); - array_mut_mutable.register_builtin_py_impl( + let mut list_mut_mutable = Self::builtin_methods(Some(mono(MUTABLE)), 2); + list_mut_mutable.register_builtin_py_impl( PROC_UPDATE, t, Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNC_UPDATE), ); - array_mut_.register_trait_methods(array_mut_t.clone(), array_mut_mutable); + list_mut_.register_trait_methods(list_mut_t.clone(), list_mut_mutable); /* ByteArray! */ - let bytearray_mut_t = mono(BYTEARRAY); - let mut bytearray_mut = Self::builtin_mono_class(BYTEARRAY, 2); + let bytelist_mut_t = mono(BYTEARRAY); + let mut bytelist_mut = Self::builtin_mono_class(BYTEARRAY, 2); let t_append = pr_met( - ref_mut(bytearray_mut_t.clone(), None), + ref_mut(bytelist_mut_t.clone(), None), vec![kw(KW_ELEM, int_interval(IntervalOp::Closed, 0, 255))], None, vec![], NoneType, ); - bytearray_mut.register_builtin_py_impl( + bytelist_mut.register_builtin_py_impl( PROC_PUSH, t_append, Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNC_APPEND), ); - let t_copy = fn0_met(ref_(bytearray_mut_t.clone()), bytearray_mut_t.clone()); - let mut bytearray_mut_copy = Self::builtin_methods(Some(mono(COPY)), 2); - bytearray_mut_copy.register_builtin_py_impl( + let t_copy = fn0_met(ref_(bytelist_mut_t.clone()), bytelist_mut_t.clone()); + let mut bytelist_mut_copy = Self::builtin_methods(Some(mono(COPY)), 2); + bytelist_mut_copy.register_builtin_py_impl( FUNC_COPY, t_copy, Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNC_COPY), ); - bytearray_mut.register_trait_methods(bytearray_mut_t.clone(), bytearray_mut_copy); + bytelist_mut.register_trait_methods(bytelist_mut_t.clone(), bytelist_mut_copy); let t_extend = pr_met( - ref_mut(bytearray_mut_t.clone(), None), + ref_mut(bytelist_mut_t.clone(), None), vec![kw( KW_ITERABLE, poly( @@ -3190,7 +3179,7 @@ impl Context { vec![], NoneType, ); - bytearray_mut.register_builtin_py_impl( + bytelist_mut.register_builtin_py_impl( PROC_EXTEND, t_extend, Immutable, @@ -3198,7 +3187,7 @@ impl Context { Some(FUNC_EXTEND), ); let t_insert = pr_met( - ref_mut(bytearray_mut_t.clone(), None), + ref_mut(bytelist_mut_t.clone(), None), vec![ kw(KW_INDEX, Nat), kw(KW_ELEM, int_interval(IntervalOp::Closed, 0, 255)), @@ -3207,7 +3196,7 @@ impl Context { vec![], NoneType, ); - bytearray_mut.register_builtin_py_impl( + bytelist_mut.register_builtin_py_impl( PROC_INSERT, t_insert, Immutable, @@ -3215,18 +3204,18 @@ impl Context { Some(FUNC_INSERT), ); let t_pop = pr0_met( - ref_mut(bytearray_mut_t.clone(), None), + ref_mut(bytelist_mut_t.clone(), None), int_interval(IntervalOp::Closed, 0, 255), ); - bytearray_mut.register_builtin_py_impl( + bytelist_mut.register_builtin_py_impl( PROC_POP, t_pop, Immutable, Visibility::BUILTIN_PUBLIC, Some(FUNC_POP), ); - let t_reverse = pr0_met(ref_mut(bytearray_mut_t.clone(), None), NoneType); - bytearray_mut.register_builtin_py_impl( + let t_reverse = pr0_met(ref_mut(bytelist_mut_t.clone(), None), NoneType); + bytelist_mut.register_builtin_py_impl( PROC_REVERSE, t_reverse, Immutable, @@ -3445,7 +3434,7 @@ impl Context { base_exception.register_superclass(Obj, &obj); base_exception.register_builtin_erg_impl( ATTR_ARGS, - unknown_len_array_t(Str), + unknown_len_list_t(Str), Immutable, Visibility::BUILTIN_PUBLIC, ); @@ -3695,20 +3684,20 @@ impl Context { Some(MODULE_TYPE), ); self.register_builtin_type( - mono(GENERIC_ARRAY), - generic_array, + mono(GENERIC_LIST), + generic_list, vis.clone(), Const, - Some(ARRAY), + Some(LIST), ); self.register_builtin_type( - unsized_array_t, - unsized_array, + unsized_list_t, + unsized_list, vis.clone(), Const, - Some(UNSIZED_ARRAY), + Some(UNSIZED_LIST), ); - self.register_builtin_type(arr_t, array_, vis.clone(), Const, Some(ARRAY)); + self.register_builtin_type(lis_t, list_, vis.clone(), Const, Some(LIST)); self.register_builtin_type(mono(SLICE), slice, vis.clone(), Const, Some(FUNC_SLICE)); self.register_builtin_type( mono(GENERIC_SET), @@ -3753,11 +3742,11 @@ impl Context { Some(FUNC_STR_ITERATOR), ); self.register_builtin_type( - poly(ARRAY_ITERATOR, vec![ty_tp(T.clone())]), - array_iterator, + poly(LIST_ITERATOR, vec![ty_tp(T.clone())]), + list_iterator, Visibility::BUILTIN_PRIVATE, Const, - Some(FUNC_ARRAY_ITERATOR), + Some(FUNC_LIST_ITERATOR), ); self.register_builtin_type( poly(SET_ITERATOR, vec![ty_tp(T.clone())]), @@ -3851,10 +3840,10 @@ impl Context { Some(MEMORYVIEW), ); self.register_builtin_type(mono(MUT_FILE), file_mut, vis.clone(), Const, Some(FILE)); - self.register_builtin_type(array_mut_t, array_mut_, vis.clone(), Const, Some(ARRAY)); + self.register_builtin_type(list_mut_t, list_mut_, vis.clone(), Const, Some(LIST)); self.register_builtin_type( - bytearray_mut_t, - bytearray_mut, + bytelist_mut_t, + bytelist_mut, vis.clone(), Const, Some(BYTEARRAY), diff --git a/crates/erg_compiler/context/initialize/const_func.rs b/crates/erg_compiler/context/initialize/const_func.rs index 1c7637cf7..1882024ce 100644 --- a/crates/erg_compiler/context/initialize/const_func.rs +++ b/crates/erg_compiler/context/initialize/const_func.rs @@ -186,14 +186,14 @@ pub(crate) fn structural_func(mut args: ValueArgs, ctx: &Context) -> EvalValueRe Ok(ValueObj::gen_t(GenTypeObj::structural(t, base)).into()) } -pub(crate) fn __array_getitem__(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { +pub(crate) fn __list_getitem__(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { let slf = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let slf = match ctx.convert_value_into_array(slf) { + let slf = match ctx.convert_value_into_list(slf) { Ok(slf) => slf, Err(val) => { - return Err(type_mismatch("Array", val, "Self")); + return Err(type_mismatch("List", val, "Self")); } }; let index = args @@ -369,7 +369,7 @@ pub(crate) fn dict_keys(mut args: ValueArgs, ctx: &Context) -> EvalValueResult>().into()).into()) + Ok(ValueObj::List(slf.into_keys().collect::>().into()).into()) } } @@ -396,7 +396,7 @@ pub(crate) fn dict_values(mut args: ValueArgs, ctx: &Context) -> EvalValueResult // let values = poly(DICT_VALUES, vec![ty_tp(union)]); Ok(ValueObj::builtin_type(union).into()) } else { - Ok(ValueObj::Array(slf.into_values().collect::>().into()).into()) + Ok(ValueObj::List(slf.into_values().collect::>().into()).into()) } } @@ -423,7 +423,7 @@ pub(crate) fn dict_items(mut args: ValueArgs, ctx: &Context) -> EvalValueResult< // let items = poly(DICT_ITEMS, vec![ty_tp(union)]); Ok(ValueObj::builtin_type(union).into()) } else { - Ok(ValueObj::Array( + Ok(ValueObj::List( slf.into_iter() .map(|(k, v)| ValueObj::Tuple(vec![k, v].into())) .collect::>() @@ -468,12 +468,12 @@ pub(crate) fn dict_diff(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult< } /// `[Int, Str].union() == Int or Str` -pub(crate) fn array_union(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { +pub(crate) fn list_union(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { let slf = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let ValueObj::Array(slf) = slf else { - return Err(type_mismatch("Array", slf, "Self")); + let ValueObj::List(slf) = slf else { + return Err(type_mismatch("List", slf, "Self")); }; let slf = slf .iter() @@ -485,15 +485,15 @@ pub(crate) fn array_union(mut args: ValueArgs, ctx: &Context) -> EvalValueResult Ok(ValueObj::builtin_type(union).into()) } -fn _arr_shape(arr: ValueObj, ctx: &Context) -> Result, String> { +fn _lis_shape(arr: ValueObj, ctx: &Context) -> Result, String> { let mut shape = vec![]; let mut arr = arr; loop { match arr { - ValueObj::Array(a) => { + ValueObj::List(a) => { shape.push(ValueObj::from(a.len()).into()); match a.first() { - Some(arr_ @ (ValueObj::Array(_) | ValueObj::Type(_))) => { + Some(arr_ @ (ValueObj::List(_) | ValueObj::Type(_))) => { arr = arr_.clone(); } _ => { @@ -501,7 +501,7 @@ fn _arr_shape(arr: ValueObj, ctx: &Context) -> Result, String> { } } } - ValueObj::Type(ref t) if &t.typ().qual_name()[..] == "Array" => { + ValueObj::Type(ref t) if &t.typ().qual_name()[..] == "List" => { let mut tps = t.typ().typarams(); let elem = match ctx.convert_tp_into_type(tps.remove(0)) { Ok(elem) => elem, @@ -522,23 +522,23 @@ fn _arr_shape(arr: ValueObj, ctx: &Context) -> Result, String> { } /// ```erg -/// Array(Int, 2).shape() == [2,] -/// Array(Array(Int, 2), N).shape() == [N, 2] +/// List(Int, 2).shape() == [2,] +/// List(List(Int, 2), N).shape() == [N, 2] /// [1, 2].shape() == [2,] /// [[1, 2], [3, 4], [5, 6]].shape() == [3, 2] /// ``` -pub(crate) fn array_shape(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_shape(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let res = _arr_shape(arr, ctx).unwrap(); - let arr = TyParam::Array(res); - Ok(arr) + let res = _lis_shape(val, ctx).unwrap(); + let lis = TyParam::List(res); + Ok(lis) } -fn _array_scalar_type(mut typ: Type, ctx: &Context) -> Result { +fn _list_scalar_type(mut typ: Type, ctx: &Context) -> Result { loop { - if matches!(&typ.qual_name()[..], "Array" | "Array!" | "UnsizedArray") { + if matches!(&typ.qual_name()[..], "List" | "List!" | "UnsizedList") { let tp = typ.typarams().remove(0); match ctx.convert_tp_into_type(tp) { Ok(typ_) => { @@ -554,21 +554,21 @@ fn _array_scalar_type(mut typ: Type, ctx: &Context) -> Result { } } -pub(crate) fn array_scalar_type(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { +pub(crate) fn list_scalar_type(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { let slf = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; let Ok(slf) = ctx.convert_value_into_type(slf.clone()) else { return Err(type_mismatch("Type", slf, "Self")); }; - let res = _array_scalar_type(slf, ctx).unwrap(); + let res = _list_scalar_type(slf, ctx).unwrap(); Ok(TyParam::t(res)) } fn _scalar_type(mut value: ValueObj, _ctx: &Context) -> Result { loop { match value { - ValueObj::Array(a) => match a.first() { + ValueObj::List(a) => match a.first() { Some(elem) => { value = elem.clone(); } @@ -592,7 +592,7 @@ fn _scalar_type(mut value: ValueObj, _ctx: &Context) -> Result { return Ok(Type::Never); } }, - ValueObj::UnsizedArray(a) => { + ValueObj::UnsizedList(a) => { value = *a.clone(); } other => { @@ -608,17 +608,17 @@ fn _scalar_type(mut value: ValueObj, _ctx: &Context) -> Result { /// ``` #[allow(unused)] pub(crate) fn scalar_type(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let res = _scalar_type(arr, ctx).unwrap(); - let arr = TyParam::t(res); - Ok(arr) + let res = _scalar_type(val, ctx).unwrap(); + let lis = TyParam::t(res); + Ok(lis) } -fn _array_sum(arr: ValueObj, _ctx: &Context) -> Result { +fn _list_sum(arr: ValueObj, _ctx: &Context) -> Result { match arr { - ValueObj::Array(a) => { + ValueObj::List(a) => { let mut sum = 0f64; for v in a.iter() { match v { @@ -657,18 +657,18 @@ fn _array_sum(arr: ValueObj, _ctx: &Context) -> Result { /// ```erg /// [1, 2].sum() == [3,] /// ``` -pub(crate) fn array_sum(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_sum(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let res = _array_sum(arr, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_sum(val, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } -fn _array_prod(arr: ValueObj, _ctx: &Context) -> Result { - match arr { - ValueObj::Array(a) => { +fn _list_prod(lis: ValueObj, _ctx: &Context) -> Result { + match lis { + ValueObj::List(a) => { let mut prod = 1f64; for v in a.iter() { match v { @@ -700,63 +700,63 @@ fn _array_prod(arr: ValueObj, _ctx: &Context) -> Result { Ok(ValueObj::Float(prod)) } } - _ => Err(format!("Cannot prod {arr}")), + _ => Err(format!("Cannot prod {lis}")), } } /// ```erg /// [1, 2].prod() == [2,] /// ``` -pub(crate) fn array_prod(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_prod(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let res = _array_prod(arr, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_prod(val, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } -fn _array_reversed(arr: ValueObj, _ctx: &Context) -> Result { - match arr { - ValueObj::Array(a) => { +fn _list_reversed(lis: ValueObj, _ctx: &Context) -> Result { + match lis { + ValueObj::List(a) => { let mut vec = a.to_vec(); vec.reverse(); - Ok(ValueObj::Array(vec.into())) + Ok(ValueObj::List(vec.into())) } - _ => Err(format!("Cannot reverse {arr}")), + _ => Err(format!("Cannot reverse {lis}")), } } -pub(crate) fn array_reversed(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_reversed(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; - let res = _array_reversed(arr, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_reversed(val, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } -fn _array_insert_at( - arr: ValueObj, +fn _list_insert_at( + lis: ValueObj, index: usize, value: ValueObj, _ctx: &Context, ) -> Result { - match arr { - ValueObj::Array(a) => { + match lis { + ValueObj::List(a) => { let mut a = a.to_vec(); if index > a.len() { return Err(format!("Index out of range: {index}")); } a.insert(index, value); - Ok(ValueObj::Array(a.into())) + Ok(ValueObj::List(a.into())) } - _ => Err(format!("Cannot insert into {arr}")), + _ => Err(format!("Cannot insert into {lis}")), } } -pub(crate) fn array_insert_at(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_insert_at(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let lis = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; let index = args @@ -768,27 +768,27 @@ pub(crate) fn array_insert_at(mut args: ValueArgs, ctx: &Context) -> EvalValueRe let Ok(index) = usize::try_from(&index) else { return Err(type_mismatch("Nat", index, "Index")); }; - let res = _array_insert_at(arr, index, value, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_insert_at(lis, index, value, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } -fn _array_remove_at(arr: ValueObj, index: usize, _ctx: &Context) -> Result { - match arr { - ValueObj::Array(a) => { +fn _list_remove_at(lis: ValueObj, index: usize, _ctx: &Context) -> Result { + match lis { + ValueObj::List(a) => { let mut a = a.to_vec(); if index >= a.len() { return Err(format!("Index out of range: {index}")); } a.remove(index); - Ok(ValueObj::Array(a.into())) + Ok(ValueObj::List(a.into())) } - _ => Err(format!("Cannot remove from {arr}")), + _ => Err(format!("Cannot remove from {lis}")), } } -pub(crate) fn array_remove_at(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_remove_at(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; let index = args @@ -797,32 +797,32 @@ pub(crate) fn array_remove_at(mut args: ValueArgs, ctx: &Context) -> EvalValueRe let Ok(index) = usize::try_from(&index) else { return Err(type_mismatch("Nat", index, "Index")); }; - let res = _array_remove_at(arr, index, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_remove_at(val, index, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } -fn _array_remove_all(arr: ValueObj, value: ValueObj, _ctx: &Context) -> Result { - match arr { - ValueObj::Array(a) => { +fn _list_remove_all(lis: ValueObj, value: ValueObj, _ctx: &Context) -> Result { + match lis { + ValueObj::List(a) => { let mut a = a.to_vec(); a.retain(|v| v != &value); - Ok(ValueObj::Array(a.into())) + Ok(ValueObj::List(a.into())) } - _ => Err(format!("Cannot remove from {arr}")), + _ => Err(format!("Cannot remove from {lis}")), } } -pub(crate) fn array_remove_all(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { - let arr = args +pub(crate) fn list_remove_all(mut args: ValueArgs, ctx: &Context) -> EvalValueResult { + let val = args .remove_left_or_key("Self") .ok_or_else(|| not_passed("Self"))?; let value = args .remove_left_or_key("Value") .ok_or_else(|| not_passed("Value"))?; - let res = _array_remove_all(arr, value, ctx).unwrap(); - let arr = TyParam::Value(res); - Ok(arr) + let res = _list_remove_all(val, value, ctx).unwrap(); + let lis = TyParam::Value(res); + Ok(lis) } pub(crate) fn __range_getitem__(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult { @@ -1058,7 +1058,7 @@ pub(crate) fn str_join(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), ValueObj::Dict(d) => d.into_keys().collect(), @@ -1136,7 +1136,7 @@ pub(crate) fn all_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1162,7 +1162,7 @@ pub(crate) fn any_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1191,7 +1191,7 @@ pub(crate) fn filter_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult .remove_left_or_key("iterable") .ok_or_else(|| not_passed("iterable"))?; let arr = match iterable { - ValueObj::Array(a) => a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1223,7 +1223,7 @@ pub(crate) fn filter_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult } } } - Ok(TyParam::Value(ValueObj::Array(filtered.into()))) + Ok(TyParam::Value(ValueObj::List(filtered.into()))) } pub(crate) fn len_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult { @@ -1231,7 +1231,7 @@ pub(crate) fn len_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.len(), + ValueObj::List(a) => a.len(), ValueObj::Tuple(t) => t.len(), ValueObj::Set(s) => s.len(), ValueObj::Dict(d) => d.len(), @@ -1252,7 +1252,7 @@ pub(crate) fn map_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1277,7 +1277,7 @@ pub(crate) fn map_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult EvalValueResult { @@ -1285,7 +1285,7 @@ pub(crate) fn max_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1320,7 +1320,7 @@ pub(crate) fn min_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1365,7 +1365,7 @@ pub(crate) fn reversed_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueRes .remove_left_or_key("reversible") .ok_or_else(|| not_passed("reversible"))?; let arr = match reversible { - ValueObj::Array(a) => a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), _ => { return Err(type_mismatch("Reversible", reversible, "reversible")); @@ -1375,7 +1375,7 @@ pub(crate) fn reversed_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueRes for v in arr.into_iter().rev() { reversed.push(v); } - Ok(TyParam::Value(ValueObj::Array(reversed.into()))) + Ok(TyParam::Value(ValueObj::List(reversed.into()))) } pub(crate) fn str_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult { @@ -1390,7 +1390,7 @@ pub(crate) fn sum_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), ValueObj::Dict(d) => d.into_keys().collect(), @@ -1502,7 +1502,7 @@ pub(crate) fn zip_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1510,7 +1510,7 @@ pub(crate) fn zip_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult a.to_vec(), + ValueObj::List(a) => a.to_vec(), ValueObj::Tuple(t) => t.to_vec(), ValueObj::Set(s) => s.into_iter().collect(), _ => { @@ -1521,7 +1521,7 @@ pub(crate) fn zip_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult ClassInfo + kw(KW_CLASSINFO, ClassType | unknown_len_list_t(ClassType)), // TODO: => ClassInfo ], None, Bool, @@ -190,7 +184,7 @@ impl Context { let t_issubclass = nd_func( vec![ kw(KW_SUBCLASS, ClassType), - kw(KW_CLASSINFO, ClassType | unknown_len_array_t(ClassType)), // TODO: => ClassInfo + kw(KW_CLASSINFO, ClassType | unknown_len_list_t(ClassType)), // TODO: => ClassInfo ], None, Bool, @@ -216,6 +210,12 @@ impl Context { t_len.clone(), None, ))); + let t_list = no_var_func( + vec![], + vec![kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())]))], + list_t(T.clone(), TyParam::erased(Nat)), + ) + .quantify(); let t_log = func( vec![], Some(kw(KW_OBJECTS, ref_(Obj))), @@ -341,7 +341,7 @@ impl Context { let t_sorted = nd_func( vec![kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())]))], None, - array_t(T.clone(), TyParam::erased(Nat)), + list_t(T.clone(), TyParam::erased(Nat)), ) .quantify(); let t_staticmethod = nd_func(vec![kw(KW_FUNC, F.clone())], None, F.clone()).quantify(); @@ -411,7 +411,7 @@ impl Context { Some(FUNC_ANY), Some(33), ); - self.register_py_builtin(FUNC_ARRAY, t_array, Some(FUNC_LIST), 215); + self.register_py_builtin(FUNC_LIST, t_list, Some(FUNC_LIST), 215); self.register_py_builtin(FUNC_ASCII, t_ascii, Some(FUNC_ASCII), 53); // Leave as `Const`, as it may negatively affect assert casting. let name = if PYTHON_MODE { FUNC_ASSERT } else { "assert__" }; diff --git a/crates/erg_compiler/context/initialize/mod.rs b/crates/erg_compiler/context/initialize/mod.rs index 9de14f2cd..20e239b71 100644 --- a/crates/erg_compiler/context/initialize/mod.rs +++ b/crates/erg_compiler/context/initialize/mod.rs @@ -258,10 +258,10 @@ const GENERIC_MODULE: &str = "GenericModule"; const PATH: &str = "Path"; const MODULE: &str = "Module"; const PY_MODULE: &str = "PyModule"; -const GENERIC_ARRAY: &str = "GenericArray"; -const UNSIZED_ARRAY: &str = "UnsizedArray"; -const ARRAY: &str = "Array"; -const MUT_ARRAY: &str = "Array!"; +const GENERIC_LIST: &str = "GenericList"; +const UNSIZED_LIST: &str = "UnsizedList"; +const LIST: &str = "List"; +const MUT_LIST: &str = "List!"; const FUNC_UPDATE_NTH: &str = "update_nth"; const PROC_UPDATE_NTH: &str = "update_nth!"; const FUNC_PARTITION: &str = "partition"; @@ -273,7 +273,7 @@ const FUNC_REPEAT: &str = "repeat"; const PROC_PUSH: &str = "push!"; const FUNC_MERGE: &str = "merge"; const PROC_MERGE: &str = "merge!"; -const ARRAY_ITERATOR: &str = "ArrayIterator"; +const LIST_ITERATOR: &str = "ListIterator"; const GENERIC_SET: &str = "GenericSet"; const SET: &str = "Set"; const MUT_SET: &str = "Set!"; @@ -375,7 +375,7 @@ const FUNC_DICT: &str = "dict"; const FUNC_TUPLE: &str = "tuple"; const UNION: &str = "Union"; const FUNC_STR_ITERATOR: &str = "str_iterator"; -const FUNC_ARRAY_ITERATOR: &str = "array_iterator"; +const FUNC_LIST_ITERATOR: &str = "list_iterator"; const FUNC_SET_ITERATOR: &str = "set_iterator"; const FUNC_TUPLE_ITERATOR: &str = "tuple_iterator"; const FUNC_ENUMERATE: &str = "enumerate"; @@ -391,7 +391,7 @@ const FUNC_NTH: &str = "nth"; const FUNC_SKIP: &str = "skip"; const FUNC_POSITION: &str = "position"; const FUNC_CHAIN: &str = "chain"; -const FUNC_INTO_ARRAY: &str = "into_array"; +const FUNC_TO_LIST: &str = "to_list"; const FILE: &str = "File"; const CALLABLE: &str = "Callable"; const GENERATOR: &str = "Generator"; @@ -478,7 +478,6 @@ const USER_WARNING: &str = "UserWarning"; const FUNC_RANGE: &str = "range"; const FUNC_ALL: &str = "all"; const FUNC_ANY: &str = "any"; -const FUNC_ARRAY: &str = "array"; const FUNC_ASCII: &str = "ascii"; const FUNC_ASSERT: &str = "assert"; const FUNC_BIN: &str = "bin"; @@ -1071,7 +1070,7 @@ impl Context { }; let qual_name = t.qual_name(); let name = VarName::from_str(t.local_name()); - // e.g Array!: |T, N|(_: {T}, _:= {N}) -> {Array!(T, N)} + // e.g. List!: |T, N|(_: {T}, _:= {N}) -> {List!(T, N)} let nd_params = ctx .params_spec .iter() diff --git a/crates/erg_compiler/context/initialize/procs.rs b/crates/erg_compiler/context/initialize/procs.rs index 0092a3f94..360382d4c 100644 --- a/crates/erg_compiler/context/initialize/procs.rs +++ b/crates/erg_compiler/context/initialize/procs.rs @@ -30,7 +30,7 @@ impl Context { let t_dir = no_var_proc( vec![], vec![kw("object", ref_(Obj))], - array_t(Str, TyParam::erased(Nat)), + list_t(Str, TyParam::erased(Nat)), ); let t_print = proc( vec![], diff --git a/crates/erg_compiler/context/initialize/traits.rs b/crates/erg_compiler/context/initialize/traits.rs index 3110db110..23f1cf094 100644 --- a/crates/erg_compiler/context/initialize/traits.rs +++ b/crates/erg_compiler/context/initialize/traits.rs @@ -80,7 +80,7 @@ impl Context { ); readable.register_builtin_decl( PROC_READLINES, - pr0_met(ref_mut(Slf, None), unknown_len_array_t(Str)), + pr0_met(ref_mut(Slf, None), unknown_len_list_t(Str)), Visibility::BUILTIN_PUBLIC, Some(FUNC_READLINES), ); @@ -263,7 +263,7 @@ impl Context { ); let ret_t = poly( TUPLE, - vec![TyParam::Array(vec![ty_tp(Nat), ty_tp(T.clone())])], + vec![TyParam::List(vec![ty_tp(Nat), ty_tp(T.clone())])], ); let t_enumerate = fn0_met(Slf.clone(), poly(ITERATOR, vec![ty_tp(ret_t)])).quantify(); iterable.register_builtin_decl( @@ -362,10 +362,10 @@ impl Context { Visibility::BUILTIN_PUBLIC, Some("Function::iterable_chain"), ); - let t_into_array = fn0_met(Slf.clone(), unknown_len_array_t(T.clone())).quantify(); + let t_to_list = fn0_met(Slf.clone(), unknown_len_list_t(T.clone())).quantify(); iterable.register_builtin_decl( - FUNC_INTO_ARRAY, - t_into_array, + FUNC_TO_LIST, + t_to_list, Visibility::BUILTIN_PUBLIC, Some("Function::list"), ); @@ -514,8 +514,8 @@ impl Context { Visibility::BUILTIN_PUBLIC, ); /* HasShape */ - let S = mono_q_tp(TY_S, instanceof(unknown_len_array_t(Nat))); - let params = vec![PS::named_nd("S", unknown_len_array_t(Nat))]; + let S = mono_q_tp(TY_S, instanceof(unknown_len_list_t(Nat))); + let params = vec![PS::named_nd("S", unknown_len_list_t(Nat))]; let has_shape = Self::builtin_poly_trait(HAS_SHAPE, params.clone(), 2); /* HasScalarType */ let Ty = mono_q_tp(TY_T, instanceof(Type)); diff --git a/crates/erg_compiler/context/inquire.rs b/crates/erg_compiler/context/inquire.rs index 6f5cc32a4..74cec7622 100644 --- a/crates/erg_compiler/context/inquire.rs +++ b/crates/erg_compiler/context/inquire.rs @@ -3690,7 +3690,7 @@ impl Context { /// ``` pub fn meta_type(&self, typ: &Type) -> Type { match typ { - Type::Poly { name, params } if &name[..] == "Array" || &name[..] == "Set" => poly( + Type::Poly { name, params } if &name[..] == "List" || &name[..] == "Set" => poly( name.clone(), params .iter() @@ -3743,7 +3743,7 @@ impl Context { /// ```erg /// recover_typarams(Int, Nat) == Nat - /// recover_typarams(Array!(Int, _), Array(Nat, 2)) == Array!(Nat, 2) + /// recover_typarams(List!(Int, _), List(Nat, 2)) == List!(Nat, 2) /// recover_typarams(Str or NoneType, {"a", "b"}) == {"a", "b"} /// ``` /// ```erg @@ -3773,7 +3773,7 @@ impl Context { ))); } } - // Array(Nat, 2) !<: Array!(Int, _) + // List(Nat, 2) !<: List!(Int, _) let base_def_t = self .get_nominal_type_ctx(base) .map(|ctx| &ctx.typ) @@ -3783,7 +3783,7 @@ impl Context { .map(|ctx| &ctx.typ) .unwrap_or(&Type::Obj); if self.related(base_def_t, assert_def_t) { - // FIXME: Vec(_), Array(Int, 2) -> Vec(2) + // FIXME: Vec(_), List(Int, 2) -> Vec(2) let casted = poly(base.qual_name(), guard.to.typarams()); Ok(casted) } else { diff --git a/crates/erg_compiler/context/instantiate.rs b/crates/erg_compiler/context/instantiate.rs index 3b27ea64a..5a52a360b 100644 --- a/crates/erg_compiler/context/instantiate.rs +++ b/crates/erg_compiler/context/instantiate.rs @@ -30,7 +30,7 @@ use crate::hir; /// For example, cloning each type variable of quantified type `?T -> ?T` would result in `?1 -> ?2`. /// To avoid this, an environment to store type variables is needed, which is `TyVarCache`. /// 量化型をインスタンス化するための文脈 -/// e.g. Array -> [("T": ?T(: Type)), ("N": ?N(: Nat))] +/// e.g. List -> [("T": ?T(: Type)), ("N": ?N(: Nat))] /// FIXME: current implementation is wrong /// It will not work unless the type variable is used with the same name as the definition. #[derive(Debug, Clone)] @@ -468,16 +468,16 @@ impl Context { .collect::>()?; Ok(TyParam::Dict(dict)) } - TyParam::Array(arr) => { - let arr = arr + TyParam::List(lis) => { + let lis = lis .into_iter() .map(|v| self.instantiate_tp(v, tmp_tv_cache, loc)) .collect::>()?; - Ok(TyParam::Array(arr)) + Ok(TyParam::List(lis)) } - TyParam::UnsizedArray(elem) => { + TyParam::UnsizedList(elem) => { let elem = self.instantiate_tp(*elem, tmp_tv_cache, loc)?; - Ok(TyParam::UnsizedArray(Box::new(elem))) + Ok(TyParam::UnsizedList(Box::new(elem))) } TyParam::Set(set) => { let set = set @@ -706,12 +706,12 @@ impl Context { Ok(ValueObj::Subr(ConstSubr::User(user))) } }, - ValueObj::Array(arr) => { + ValueObj::List(lis) => { let mut new = vec![]; - for v in arr.iter().cloned() { + for v in lis.iter().cloned() { new.push(self.instantiate_value(v, tmp_tv_cache, loc)?); } - Ok(ValueObj::Array(new.into())) + Ok(ValueObj::List(new.into())) } ValueObj::Tuple(tup) => { let mut new = vec![]; diff --git a/crates/erg_compiler/context/instantiate_spec.rs b/crates/erg_compiler/context/instantiate_spec.rs index 176bd486c..9fc2dca68 100644 --- a/crates/erg_compiler/context/instantiate_spec.rs +++ b/crates/erg_compiler/context/instantiate_spec.rs @@ -10,7 +10,7 @@ use ast::{ NonDefaultParamSignature, ParamTySpec, PreDeclTypeSpec, TypeBoundSpec, TypeBoundSpecs, TypeSpec, }; use erg_parser::ast::{ - self, ConstApp, ConstArgs, ConstArray, ConstExpr, ConstSet, Identifier, VarName, + self, ConstApp, ConstArgs, ConstExpr, ConstList, ConstSet, Identifier, VarName, VisModifierSpec, VisRestriction, }; use erg_parser::token::TokenKind; @@ -443,13 +443,13 @@ impl Context { ast::ParamPattern::Ref(_) => ref_(gen_free_t()), ast::ParamPattern::RefMut(_) => ref_mut(gen_free_t(), None), // ast::ParamPattern::VarName(name) if &name.inspect()[..] == "_" => Type::Obj, - // TODO: Array + // TODO: List _ => gen_free_t(), } }; if let Some(decl_pt) = opt_decl_t { if kind.is_var_params() { - let spec_t = unknown_len_array_t(spec_t.clone()); + let spec_t = unknown_len_list_t(spec_t.clone()); self.sub_unify( decl_pt.typ(), &spec_t, @@ -710,9 +710,9 @@ impl Context { not_found_is_qvar: bool, ) -> Failable { match name.inspect().trim_start_matches([':', '.']) { - "Array" => { + "List" => { let ctx = &self - .get_nominal_type_ctx(&array_t(Type::Obj, TyParam::Failure)) + .get_nominal_type_ctx(&list_t(Type::Obj, TyParam::Failure)) .unwrap() .ctx; // TODO: kw @@ -737,9 +737,9 @@ impl Context { } else { TyParam::erased(Nat) }; - Ok(array_t(t, len)) + Ok(list_t(t, len)) } else { - Ok(mono("GenericArray")) + Ok(mono("GenericList")) } } "Ref" => { @@ -1250,7 +1250,7 @@ impl Context { } /// erased_index: - /// e.g. `instantiate_const_expr(Array(Str, _), Some((self, 1))) => Array(Str, _: Nat)` + /// e.g. `instantiate_const_expr(List(Str, _), Some((self, 1))) => List(Str, _: Nat)` pub(crate) fn instantiate_const_expr( &self, expr: &ast::ConstExpr, @@ -1269,40 +1269,40 @@ impl Context { ast::ConstExpr::App(app) => { self.instantiate_app(app, erased_idx, tmp_tv_cache, not_found_is_qvar) } - ast::ConstExpr::Array(ConstArray::Normal(array)) => { - let mut tp_arr = vec![]; - for (i, elem) in array.elems.pos_args().enumerate() { + ast::ConstExpr::List(ConstList::Normal(list)) => { + let mut tp_lis = vec![]; + for (i, elem) in list.elems.pos_args().enumerate() { let el = self.instantiate_const_expr( &elem.expr, Some((self, i)), tmp_tv_cache, not_found_is_qvar, )?; - tp_arr.push(el); + tp_lis.push(el); } - Ok(TyParam::Array(tp_arr)) + Ok(TyParam::List(tp_lis)) } - ast::ConstExpr::Array(ConstArray::WithLength(arr)) => { + ast::ConstExpr::List(ConstList::WithLength(lis)) => { let elem = self.instantiate_const_expr( - &arr.elem, + &lis.elem, erased_idx, tmp_tv_cache, not_found_is_qvar, )?; let length = self.instantiate_const_expr( - &arr.length, + &lis.length, erased_idx, tmp_tv_cache, not_found_is_qvar, )?; if length.is_erased() { - if let Ok(elem_t) = self.instantiate_tp_as_type(elem, arr) { - return Ok(TyParam::t(unknown_len_array_t(elem_t))); + if let Ok(elem_t) = self.instantiate_tp_as_type(elem, lis) { + return Ok(TyParam::t(unknown_len_list_t(elem_t))); } } type_feature_error!( self, - arr.loc(), + lis.loc(), &format!("instantiating const expression {expr}") ) } @@ -1636,14 +1636,14 @@ impl Context { TyParam::Value(value) => self.convert_value_into_type(value).or_else(|value| { type_feature_error!(self, loc.loc(), &format!("instantiate `{value}` as type")) }), - TyParam::Array(arr) => { - let len = TyParam::value(arr.len()); + TyParam::List(lis) => { + let len = TyParam::value(lis.len()); let mut union = Type::Never; - for tp in arr { + for tp in lis { let t = self.instantiate_tp_as_type(tp, loc)?; union = self.union(&union, &t); } - Ok(array_t(union, len)) + Ok(list_t(union, len)) } TyParam::Set(set) => { let t = set @@ -1962,20 +1962,20 @@ impl Context { mode, not_found_is_qvar, )?)), - TypeSpec::Array(arr) => { + TypeSpec::List(lis) => { let elem_t = self.instantiate_typespec_full( - &arr.ty, + &lis.ty, opt_decl_t, tmp_tv_cache, mode, not_found_is_qvar, )?; let mut len = - self.instantiate_const_expr(&arr.len, None, tmp_tv_cache, not_found_is_qvar)?; + self.instantiate_const_expr(&lis.len, None, tmp_tv_cache, not_found_is_qvar)?; if let TyParam::Erased(t) = &mut len { *t.as_mut() = Type::Nat; } - Ok(array_t(elem_t, len)) + Ok(list_t(elem_t, len)) } TypeSpec::SetWithLen(set) => { let elem_t = self.instantiate_typespec_full( diff --git a/crates/erg_compiler/context/mod.rs b/crates/erg_compiler/context/mod.rs index 133767bab..d56bb0298 100644 --- a/crates/erg_compiler/context/mod.rs +++ b/crates/erg_compiler/context/mod.rs @@ -645,7 +645,7 @@ pub struct Context { pub(crate) mono_types: Dict, // Implementation Contexts for Polymorphic Types // Vec are specialization parameters - // e.g. {"Array": [(Array(Nat), ctx), (Array(Int), ctx), (Array(Str), ctx), (Array(Obj), ctx), (Array('T), ctx)], ...} + // e.g. {"List": [(List(Nat), ctx), (List(Int), ctx), (List(Str), ctx), (List(Obj), ctx), (List('T), ctx)], ...} pub(crate) poly_types: Dict, // patches can be accessed like normal records // but when used as a fallback to a type, values are traversed instead of accessing by keys diff --git a/crates/erg_compiler/context/register.rs b/crates/erg_compiler/context/register.rs index e75e0d0f7..13804573b 100644 --- a/crates/erg_compiler/context/register.rs +++ b/crates/erg_compiler/context/register.rs @@ -21,7 +21,7 @@ use erg_parser::ast::{self, ClassAttr, RecordAttrOrIdent, TypeSpecWithOp}; use crate::ty::constructors::{ free_var, func, func0, func1, module, proc, py_module, ref_, ref_mut, str_dict_t, tp_enum, - unknown_len_array_t, v_enum, + unknown_len_list_t, v_enum, }; use crate::ty::free::{Constraint, HasLevel}; use crate::ty::typaram::TyParam; @@ -397,7 +397,7 @@ impl Context { Err((ty, errs)) => (ty, errs), }; let spec_t = match kind { - ParamKind::VarParams => unknown_len_array_t(spec_t), + ParamKind::VarParams => unknown_len_list_t(spec_t), ParamKind::KwVarParams => str_dict_t(spec_t), _ => spec_t, }; @@ -577,7 +577,7 @@ impl Context { } if let Some(var_params) = &mut params.var_params { if let Some(pt) = &subr_t.var_params { - let pt = pt.clone().map_type(unknown_len_array_t); + let pt = pt.clone().map_type(unknown_len_list_t); if let Err(es) = self.assign_param(var_params, Some(&pt), tmp_tv_cache, ParamKind::VarParams) { @@ -2764,9 +2764,9 @@ impl Context { } res } - ast::Expr::Array(ast::Array::Normal(arr)) => { + ast::Expr::List(ast::List::Normal(lis)) => { let mut res = false; - for val in arr.elems.pos_args().iter() { + for val in lis.elems.pos_args().iter() { if self.inc_ref_expr(&val.expr, namespace, tmp_tv_cache) { res = true; } diff --git a/crates/erg_compiler/context/unify.rs b/crates/erg_compiler/context/unify.rs index c6ec6a4f9..2c0d9c6ea 100644 --- a/crates/erg_compiler/context/unify.rs +++ b/crates/erg_compiler/context/unify.rs @@ -525,7 +525,7 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> { self.sub_unify(sub, &r)?; Ok(()) } - (TyParam::Array(sub), TyParam::Array(sup)) + (TyParam::List(sub), TyParam::List(sup)) | (TyParam::Tuple(sub), TyParam::Tuple(sup)) => { for (l, r) in sub.iter().zip(sup.iter()) { self.sub_unify_tp(l, r, _variance, allow_divergence)?; @@ -1208,8 +1208,8 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> { }; self.sub_unify(&sub, &new_sup)?; // ?T(:> Int, <: Int) ==> ?T == Int - // ?T(:> Array(Int, 3), <: Array(?T, ?N)) ==> ?T == Array(Int, 3) - // ?T(:> Array(Int, 3), <: Indexable(?K, ?V)) ==> ?T(:> Array(Int, 3), <: Indexable(0..2, Int)) + // ?T(:> List(Int, 3), <: List(?T, ?N)) ==> ?T == List(Int, 3) + // ?T(:> List(Int, 3), <: Indexable(?K, ?V)) ==> ?T(:> List(Int, 3), <: Indexable(0..2, Int)) if !sub.is_refinement() && new_sup.qual_name() == sub.qual_name() && !new_sup.is_unbound_var() @@ -1384,7 +1384,7 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> { }, ) => { // e.g. Set(?T) <: Eq(Set(?T)) - // Array(Str) <: Iterable(Str) + // List(Str) <: Iterable(Str) // Zip(T, U) <: Iterable(Tuple([T, U])) if ln != rn { self.nominal_sub_unify(maybe_sub, maybe_sup, rps)?; @@ -1542,7 +1542,7 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> { (Subr(_) | Record(_), Type) => {} (Guard(_), Bool) | (Bool, Guard(_)) => {} // REVIEW: correct? - (Poly { name, .. }, Type) if &name[..] == "Array" || &name[..] == "Tuple" => {} + (Poly { name, .. }, Type) if &name[..] == "List" || &name[..] == "Tuple" => {} (Poly { .. }, _) => { if maybe_sub.has_no_qvar() && maybe_sup.has_no_qvar() { return Ok(()); diff --git a/crates/erg_compiler/declare.rs b/crates/erg_compiler/declare.rs index aa2155c73..654bfa8d9 100644 --- a/crates/erg_compiler/declare.rs +++ b/crates/erg_compiler/declare.rs @@ -12,7 +12,7 @@ use erg_parser::desugar::Desugarer; use crate::context::instantiate::TyVarCache; use crate::context::{ClassDefType, Context, MethodContext, MethodPair, TraitImpl}; use crate::lower::GenericASTLowerer; -use crate::ty::constructors::{array_t, mono, mono_q, mono_q_tp, poly, v_enum}; +use crate::ty::constructors::{list_t, mono, mono_q, mono_q_tp, poly, v_enum}; use crate::ty::free::{Constraint, HasLevel}; use crate::ty::value::{GenTypeObj, TypeObj, ValueObj}; use crate::ty::{HasType, TyParam, Type, Visibility}; @@ -288,30 +288,30 @@ impl GenericASTLowerer { Ok(hir::UnaryOp::new(unaryop.op, expr, VarInfo::default())) } - fn fake_lower_array(&self, arr: ast::Array) -> LowerResult { + fn fake_lower_list(&self, arr: ast::List) -> LowerResult { match arr { - ast::Array::WithLength(arr) => { - let len = self.fake_lower_expr(*arr.len)?; - let elem = self.fake_lower_expr(arr.elem.expr)?; - Ok(hir::Array::WithLength(hir::ArrayWithLength::new( - arr.l_sqbr, - arr.r_sqbr, + ast::List::WithLength(lis) => { + let len = self.fake_lower_expr(*lis.len)?; + let elem = self.fake_lower_expr(lis.elem.expr)?; + Ok(hir::List::WithLength(hir::ListWithLength::new( + lis.l_sqbr, + lis.r_sqbr, Type::Failure, elem, Some(len), ))) } - ast::Array::Normal(arr) => { + ast::List::Normal(lis) => { let mut elems = Vec::new(); - let (elems_, ..) = arr.elems.deconstruct(); + let (elems_, ..) = lis.elems.deconstruct(); for elem in elems_.into_iter() { let elem = self.fake_lower_expr(elem.expr)?; elems.push(hir::PosArg::new(elem)); } let elems = hir::Args::new(elems, None, vec![], None, None); - let t = array_t(Type::Failure, TyParam::value(elems.len())); - Ok(hir::Array::Normal(hir::NormalArray::new( - arr.l_sqbr, arr.r_sqbr, t, elems, + let t = list_t(Type::Failure, TyParam::value(elems.len())); + Ok(hir::List::Normal(hir::NormalList::new( + lis.l_sqbr, lis.r_sqbr, t, elems, ))) } other => Err(LowerErrors::from(LowerError::declare_error( @@ -612,7 +612,7 @@ impl GenericASTLowerer { ast::Expr::Literal(lit) => Ok(hir::Expr::Literal(self.fake_lower_literal(lit)?)), ast::Expr::BinOp(binop) => Ok(hir::Expr::BinOp(self.fake_lower_binop(binop)?)), ast::Expr::UnaryOp(unop) => Ok(hir::Expr::UnaryOp(self.fake_lower_unaryop(unop)?)), - ast::Expr::Array(arr) => Ok(hir::Expr::Array(self.fake_lower_array(arr)?)), + ast::Expr::List(lis) => Ok(hir::Expr::List(self.fake_lower_list(lis)?)), ast::Expr::Tuple(tup) => Ok(hir::Expr::Tuple(self.fake_lower_tuple(tup)?)), ast::Expr::Record(rec) => Ok(hir::Expr::Record(self.fake_lower_record(rec)?)), ast::Expr::Set(set) => Ok(hir::Expr::Set(self.fake_lower_set(set)?)), diff --git a/crates/erg_compiler/effectcheck.rs b/crates/erg_compiler/effectcheck.rs index ddc870c85..8d4bd95eb 100644 --- a/crates/erg_compiler/effectcheck.rs +++ b/crates/erg_compiler/effectcheck.rs @@ -10,7 +10,7 @@ use erg_parser::token::TokenKind; use crate::context::Context; use crate::error::{EffectError, EffectErrors}; -use crate::hir::{Array, Call, Def, Dict, Expr, Params, Set, Signature, Tuple, HIR}; +use crate::hir::{Call, Def, Dict, Expr, List, Params, Set, Signature, Tuple, HIR}; use crate::ty::{HasType, Visibility}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -134,21 +134,21 @@ impl<'c> SideEffectChecker<'c> { self.check_expr(&unary.expr); } Expr::Accessor(_) | Expr::Literal(_) => {} - Expr::Array(array) => match array { - Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter() { + Expr::List(list) => match list { + List::Normal(lis) => { + for elem in lis.elems.pos_args.iter() { self.check_expr(&elem.expr); } } - Array::WithLength(arr) => { - self.check_expr(&arr.elem); - if let Some(len) = &arr.len { + List::WithLength(lis) => { + self.check_expr(&lis.elem); + if let Some(len) = &lis.len { self.check_expr(len); } } - Array::Comprehension(arr) => { - self.check_expr(&arr.elem); - self.check_expr(&arr.guard); + List::Comprehension(lis) => { + self.check_expr(&lis.elem); + self.check_expr(&lis.guard); } }, Expr::Tuple(tuple) => match tuple { @@ -350,21 +350,21 @@ impl<'c> SideEffectChecker<'c> { self.check_expr(def); } } - Expr::Array(array) => match array { - Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter() { + Expr::List(list) => match list { + List::Normal(lis) => { + for elem in lis.elems.pos_args.iter() { self.check_expr(&elem.expr); } } - Array::WithLength(arr) => { - self.check_expr(&arr.elem); - if let Some(len) = &arr.len { + List::WithLength(lis) => { + self.check_expr(&lis.elem); + if let Some(len) = &lis.len { self.check_expr(len); } } - Array::Comprehension(arr) => { - self.check_expr(&arr.elem); - self.check_expr(&arr.guard); + List::Comprehension(lis) => { + self.check_expr(&lis.elem); + self.check_expr(&lis.guard); } }, Expr::Tuple(tuple) => match tuple { @@ -538,15 +538,15 @@ impl<'c> SideEffectChecker<'c> { } Expr::BinOp(bin) => Self::is_impure(&bin.lhs) || Self::is_impure(&bin.rhs), Expr::UnaryOp(unary) => Self::is_impure(&unary.expr), - Expr::Array(arr) => match arr { - Array::Normal(arr) => arr + Expr::List(lis) => match lis { + List::Normal(lis) => lis .elems .pos_args .iter() .any(|elem| Self::is_impure(&elem.expr)), - Array::WithLength(arr) => { - Self::is_impure(&arr.elem) - || arr.len.as_ref().map_or(false, |len| Self::is_impure(len)) + List::WithLength(lis) => { + Self::is_impure(&lis.elem) + || lis.len.as_ref().map_or(false, |len| Self::is_impure(len)) } _ => todo!(), }, diff --git a/crates/erg_compiler/hir.rs b/crates/erg_compiler/hir.rs index 1b4da21aa..8618aaea9 100644 --- a/crates/erg_compiler/hir.rs +++ b/crates/erg_compiler/hir.rs @@ -744,7 +744,7 @@ impl Accessor { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayWithLength { +pub struct ListWithLength { pub l_sqbr: Token, pub r_sqbr: Token, pub t: Type, @@ -752,7 +752,7 @@ pub struct ArrayWithLength { pub len: Option>, } -impl NestedDisplay for ArrayWithLength { +impl NestedDisplay for ListWithLength { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!( f, @@ -764,7 +764,7 @@ impl NestedDisplay for ArrayWithLength { } } -impl NoTypeDisplay for ArrayWithLength { +impl NoTypeDisplay for ListWithLength { fn to_string_notype(&self) -> String { format!( "[{}; {}]", @@ -774,11 +774,11 @@ impl NoTypeDisplay for ArrayWithLength { } } -impl_display_from_nested!(ArrayWithLength); -impl_locational!(ArrayWithLength, l_sqbr, elem, r_sqbr); -impl_t!(ArrayWithLength); +impl_display_from_nested!(ListWithLength); +impl_locational!(ListWithLength, l_sqbr, elem, r_sqbr); +impl_t!(ListWithLength); -impl ArrayWithLength { +impl ListWithLength { pub fn new(l_sqbr: Token, r_sqbr: Token, t: Type, elem: Expr, len: Option) -> Self { Self { l_sqbr, @@ -796,7 +796,7 @@ impl ArrayWithLength { // TODO: generators #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayComprehension { +pub struct ListComprehension { pub l_sqbr: Token, pub r_sqbr: Token, pub t: Type, @@ -804,13 +804,13 @@ pub struct ArrayComprehension { pub guard: Box, } -impl NestedDisplay for ArrayComprehension { +impl NestedDisplay for ListComprehension { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!(f, "[{} | {}](: {})", self.elem, self.guard, self.t) } } -impl NoTypeDisplay for ArrayComprehension { +impl NoTypeDisplay for ListComprehension { fn to_string_notype(&self) -> String { format!( "[{} | {}]", @@ -820,19 +820,19 @@ impl NoTypeDisplay for ArrayComprehension { } } -impl_display_from_nested!(ArrayComprehension); -impl_locational!(ArrayComprehension, l_sqbr, elem, r_sqbr); -impl_t!(ArrayComprehension); +impl_display_from_nested!(ListComprehension); +impl_locational!(ListComprehension, l_sqbr, elem, r_sqbr); +impl_t!(ListComprehension); #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NormalArray { +pub struct NormalList { pub l_sqbr: Token, pub r_sqbr: Token, pub t: Type, pub elems: Args, } -impl NestedDisplay for NormalArray { +impl NestedDisplay for NormalList { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { writeln!(f, "[")?; self.elems.fmt_nest(f, level + 1)?; @@ -840,7 +840,7 @@ impl NestedDisplay for NormalArray { } } -impl NoTypeDisplay for NormalArray { +impl NoTypeDisplay for NormalList { fn to_string_notype(&self) -> String { format!( "[{}]", @@ -854,11 +854,11 @@ impl NoTypeDisplay for NormalArray { } } -impl_display_from_nested!(NormalArray); -impl_locational!(NormalArray, l_sqbr, elems, r_sqbr); -impl_t!(NormalArray); +impl_display_from_nested!(NormalList); +impl_locational!(NormalList, l_sqbr, elems, r_sqbr); +impl_t!(NormalList); -impl NormalArray { +impl NormalList { pub fn new(l_sqbr: Token, r_sqbr: Token, t: Type, elems: Args) -> Self { Self { l_sqbr, @@ -874,21 +874,21 @@ impl NormalArray { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Array { - Normal(NormalArray), - Comprehension(ArrayComprehension), - WithLength(ArrayWithLength), +pub enum List { + Normal(NormalList), + Comprehension(ListComprehension), + WithLength(ListWithLength), } -impl_nested_display_for_enum!(Array; Normal, Comprehension, WithLength); -impl_no_type_display_for_enum!(Array; Normal, Comprehension, WithLength); -impl_display_for_enum!(Array; Normal, Comprehension, WithLength); -impl_locational_for_enum!(Array; Normal, Comprehension, WithLength); -impl_t_for_enum!(Array; Normal, Comprehension, WithLength); +impl_nested_display_for_enum!(List; Normal, Comprehension, WithLength); +impl_no_type_display_for_enum!(List; Normal, Comprehension, WithLength); +impl_display_for_enum!(List; Normal, Comprehension, WithLength); +impl_locational_for_enum!(List; Normal, Comprehension, WithLength); +impl_t_for_enum!(List; Normal, Comprehension, WithLength); -impl Array { +impl List { pub const fn is_unsized(&self) -> bool { - matches!(self, Self::WithLength(arr) if arr.is_unsized()) + matches!(self, Self::WithLength(lis) if lis.is_unsized()) } } @@ -2733,7 +2733,7 @@ impl TypeAscription { pub enum Expr { Literal(Literal), Accessor(Accessor), - Array(Array), + List(List), Tuple(Tuple), Set(Set), Dict(Dict), @@ -2753,13 +2753,13 @@ pub enum Expr { Dummy(Dummy), // for mapping to Python AST } -impl_nested_display_for_chunk_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); -impl_no_type_display_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_nested_display_for_chunk_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_no_type_display_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); impl_display_from_nested!(Expr); -impl_locational_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); -impl_t_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); -impl_from_trait_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Set, Dummy); -impl_try_from_trait_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Set, Dummy); +impl_locational_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_t_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_from_trait_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Set, Dummy); +impl_try_from_trait_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, ReDef, Set, Dummy); impl Default for Expr { fn default() -> Self { @@ -2849,7 +2849,7 @@ impl Expr { match self { Self::Literal(_) => "literal", Self::Accessor(_) => "accessor", - Self::Array(_) => "array", + Self::List(_) => "array", Self::Tuple(_) => "tuple", Self::Dict(_) => "dict", Self::Set(_) => "set", @@ -2945,9 +2945,9 @@ impl Expr { } sum } - Self::Array(Array::Normal(arr)) => { + Self::List(List::Normal(lis)) => { let mut sum = 0; - for elem in arr.elems.pos_args.iter() { + for elem in lis.elems.pos_args.iter() { sum += elem.expr.complexity(); } sum diff --git a/crates/erg_compiler/lib/core.d/Array!.d.er b/crates/erg_compiler/lib/core.d/List!.d.er similarity index 72% rename from crates/erg_compiler/lib/core.d/Array!.d.er rename to crates/erg_compiler/lib/core.d/List!.d.er index fca489a7f..888abbd9b 100644 --- a/crates/erg_compiler/lib/core.d/Array!.d.er +++ b/crates/erg_compiler/lib/core.d/List!.d.er @@ -1,9 +1,9 @@ # TODO: transition specifications -array = pyimport "Array" +array = pyimport "List" -.Array!: ClassType -.Array! <: array.Array -.Array!. +.List!: ClassType +.List! <: array.List +.List!. ''' Append object to the end of the list. ''' @@ -12,7 +12,7 @@ array = pyimport "Array" arr.push! 3 assert arr == [1, 2, 3] ''' - push!: |T, N: Nat|(self: Array!(T, N), elem: T) => NoneType + push!: |T, N: Nat|(self: List!(T, N), elem: T) => NoneType ''' Extend the list by appending all the items from `iterable`. ''' @@ -21,7 +21,7 @@ array = pyimport "Array" arr.extend! [3, 4] assert arr == [1, 2, 3, 4] ''' - extend!: |T, N: Nat|(self: Array!(T, N), iterable: Iterable(T)) => NoneType + extend!: |T, N: Nat|(self: List!(T, N), iterable: Iterable(T)) => NoneType ''' Insert `elem` before `index`. ''' @@ -30,7 +30,7 @@ array = pyimport "Array" arr.insert! 0, 3 assert arr == [3, 1, 2] ''' - insert!: |T, N: Nat|(self: Array!(T, N), index: Nat, elem: T) => NoneType + insert!: |T, N: Nat|(self: List!(T, N), index: Nat, elem: T) => NoneType ''' Remove the first item from the list whose value is `value`. ''' @@ -39,7 +39,7 @@ array = pyimport "Array" arr.remove! 1 assert arr == [2] ''' - remove!: |T, N: Nat|(self: Array!(T, N), value: T) => NoneType + remove!: |T, N: Nat|(self: List!(T, N), value: T) => NoneType ''' Remove the item at the given position in the list, and return it. ''' @@ -49,7 +49,7 @@ array = pyimport "Array" assert arr == [1] assert i == 2 ''' - pop!: |T, N: Nat|(self: Array!(T, N), index := Nat or {-1}) => T + pop!: |T, N: Nat|(self: List!(T, N), index := Nat or {-1}) => T ''' Remove all items from the list. ''' @@ -58,7 +58,7 @@ array = pyimport "Array" arr.clear!() assert arr == [] ''' - clear!: |T, N: Nat|(self: Array!(T, N)) => NoneType + clear!: |T, N: Nat|(self: List!(T, N)) => NoneType ''' Sort the list in ascending order and return `None`. @@ -75,7 +75,7 @@ array = pyimport "Array" arr.sort!() assert arr == [1, 2, 3] ''' - sort!: |T, N: Nat|(self: Array!(T, N)) => NoneType + sort!: |T, N: Nat|(self: List!(T, N)) => NoneType ''' Reverse the elements of the list in-place and return `None`. ''' @@ -84,7 +84,7 @@ array = pyimport "Array" arr.reverse!() assert arr == [2, 1, 3] ''' - reverse!: |T, N: Nat|(self: Array!(T, N)) => NoneType + reverse!: |T, N: Nat|(self: List!(T, N)) => NoneType ''' Update each element of the array according to the passed function `f`. ''' @@ -93,7 +93,7 @@ array = pyimport "Array" arr.strict_map! x -> x + 1 assert arr == [3, 4] ''' - strict_map!: |T, N: Nat|(self: Array!(T, N), f: T -> T) => NoneType + strict_map!: |T, N: Nat|(self: List!(T, N), f: T -> T) => NoneType ''' Update `index`-th element of the array according to the passed function `f`. ''' @@ -102,7 +102,7 @@ array = pyimport "Array" arr.udpate_nth! 0, x -> x + 1 assert arr == [2, 2] ''' - update_nth!: |T, N: Nat|(self: Array!(T, N), index: Nat, f: T -> T) => NoneType + update_nth!: |T, N: Nat|(self: List!(T, N), index: Nat, f: T -> T) => NoneType ''' Return a (deep) copy of the array. ''' @@ -113,4 +113,4 @@ array = pyimport "Array" assert arr_copy == [1, 2, 3] assert arr == [1, 2] ''' - copy: |T, N: Nat|(self: Ref(Array!(T, N))) => Array!(T, N) + copy: |T, N: Nat|(self: Ref(List!(T, N))) => List!(T, N) diff --git a/crates/erg_compiler/lib/core.d/Array.d.er b/crates/erg_compiler/lib/core.d/List.d.er similarity index 71% rename from crates/erg_compiler/lib/core.d/Array.d.er rename to crates/erg_compiler/lib/core.d/List.d.er index 94a968448..95f08ce0b 100644 --- a/crates/erg_compiler/lib/core.d/Array.d.er +++ b/crates/erg_compiler/lib/core.d/List.d.er @@ -1,12 +1,12 @@ -.Array: ClassType -.Array. +.List: ClassType +.List. ''' Concatenates two arrays. Same as `self + other`. ''' '''erg assert [1, 2].concat([3, 4]) == [1, 2, 3, 4] ''' - concat: |T: Type, M: Nat, N: Nat|(self: Array(T, M), other: Array(T, N)) -> Array(T, M + N) + concat: |T: Type, M: Nat, N: Nat|(self: List(T, M), other: List(T, N)) -> List(T, M + N) ''' Returns the number of elements in the array. ''' @@ -14,7 +14,7 @@ assert [1, 2, 3, 1, 2].count(1) == 2 assert ["a", "b", "c"].count("a") == 1 ''' - count: |T: Type, N: Nat|(self: Array(T, N), x: T) -> Nat + count: |T: Type, N: Nat|(self: List(T, N), x: T) -> Nat ''' Remove array duplicates. @@ -25,7 +25,7 @@ assert [1, 1, 2].dedup() == [1, 2] assert [0.0, 0.1, 10.0, 20.0, 20.1].dedup((lhs, rhs) -> abs(lhs - rhs) < 1.0) == [0.1, 10.0, 20.1] ''' - dedup: |T: Type|(self: Array(T, _), same_bucket := (T, T) -> Bool) -> Array(T, _) + dedup: |T: Type|(self: List(T, _), same_bucket := (T, T) -> Bool) -> List(T, _) ''' Create two arrays according to the `predicate` function. @@ -34,25 +34,25 @@ '''erg assert [-2, -1, 0, 1, 2].partition(x -> x >= 0) == ([0, 1, 2], [-2, -1]) ''' - partition: |T: Type|(self: Array(T, _), predicate: T -> Bool) -> (Array(T, _), Array(T, _)) + partition: |T: Type|(self: List(T, _), predicate: T -> Bool) -> (List(T, _), List(T, _)) ''' Returns the summation of all elements in the array. ''' '''erg assert [1, 2, 3].sum() == 6 ''' - sum: |T: Type|(self: Array(T, _), start := T) -> T + sum: |T: Type|(self: List(T, _), start := T) -> T ''' Returns the product of all elements in the array. ''' '''erg assert [1, 2, 3].product() == 6 ''' - prod: |T: Type|(self: Array(T, _), start := T) -> T + prod: |T: Type|(self: List(T, _), start := T) -> T ''' Returns the reversed array. ''' '''erg assert [1, 2, 3].reversed() == [3, 2, 1] ''' - reversed: |T: Type, N: Nat|(self: Array(T, N)) -> Array(T, N) + reversed: |T: Type, N: Nat|(self: List(T, N)) -> List(T, N) diff --git a/crates/erg_compiler/lib/core/_erg_contains_operator.py b/crates/erg_compiler/lib/core/_erg_contains_operator.py index 4331d1ba3..fa916b022 100644 --- a/crates/erg_compiler/lib/core/_erg_contains_operator.py +++ b/crates/erg_compiler/lib/core/_erg_contains_operator.py @@ -60,9 +60,9 @@ def contains_operator(y, elem) -> bool: len_check = True # It can be True even if either elem or y has the larger number of elems return type_check and len_check elif _isinstance(elem, list): - from _erg_array import Array + from _erg_list import List - return contains_operator(y, Array(elem)) + return contains_operator(y, List(elem)) elif callable(elem): # TODO: return callable(y) diff --git a/crates/erg_compiler/lib/core/_erg_array.py b/crates/erg_compiler/lib/core/_erg_list.py similarity index 83% rename from crates/erg_compiler/lib/core/_erg_array.py rename to crates/erg_compiler/lib/core/_erg_list.py index b0b3d3e78..cd5575df9 100644 --- a/crates/erg_compiler/lib/core/_erg_array.py +++ b/crates/erg_compiler/lib/core/_erg_list.py @@ -8,21 +8,21 @@ from _erg_type import UnionType -class Array(list): +class List(list): @staticmethod - def try_new(arr): # -> Result[Array] - if isinstance(arr, list): - return Array(arr) + def try_new(lis): # -> Result[List] + if isinstance(lis, list): + return List(lis) else: return Error("not a list") - def generic_try_new(arr, cls=None): # -> Result[Array] + def generic_try_new(lis, cls=None): # -> Result[List] if cls is None: - return Array.try_new(arr) + return List.try_new(lis) else: elem_t = cls.__args__[0] elems = [] - for elem in arr: + for elem in lis: if not hasattr(elem_t, "try_new"): return Error("not a " + str(elem_t)) # TODO: nested check @@ -31,11 +31,11 @@ def generic_try_new(arr, cls=None): # -> Result[Array] elems.append(elem) else: return Error("not a " + str(elem_t)) - return Array(elems) + return List(elems) def dedup(self, same_bucket=None): if same_bucket is None: - return Array(list(set(self))) + return List(list(set(self))) else: removes = [] for lhs, rhs in zip(self, self[1:]): @@ -56,20 +56,20 @@ def push(self, value): return self def partition(self, f): - return Array(list(filter(f, self))), Array( + return List(list(filter(f, self))), List( list(filter(lambda x: not f(x), self)) ) def __mul__(self, n): - return then__(list.__mul__(self, n), Array) + return then__(list.__mul__(self, n), List) def __getitem__(self, index_or_slice): if isinstance(index_or_slice, slice): - return Array(list.__getitem__(self, index_or_slice)) + return List(list.__getitem__(self, index_or_slice)) elif isinstance(index_or_slice, NatMut) or isinstance(index_or_slice, IntMut): return list.__getitem__(self, int(index_or_slice)) elif isinstance(index_or_slice, Range): - return Array(list.__getitem__(self, index_or_slice.into_slice())) + return List(list.__getitem__(self, index_or_slice.into_slice())) else: return list.__getitem__(self, index_or_slice) @@ -77,7 +77,7 @@ def __hash__(self): return hash(tuple(self)) def update(self, f): - self = Array(f(self)) + self = List(f(self)) def type_check(self, t: type) -> bool: if isinstance(t, list): @@ -114,7 +114,7 @@ def prod(self, start=1): return reduce(lambda x, y: x * y, self, start) def reversed(self): - return Array(list.__reversed__(self)) + return List(list.__reversed__(self)) def insert_at(self, index, value): self.insert(index, value) @@ -135,10 +135,10 @@ def repeat(self, n): new = [] for _ in range(n): new.extend(deepcopy(self)) - return Array(new) + return List(new) -class UnsizedArray: +class UnsizedList: elem: object def __init__(self, elem): diff --git a/crates/erg_compiler/lib/core/_erg_std_prelude.py b/crates/erg_compiler/lib/core/_erg_std_prelude.py index 2a8ed0376..58befaa6e 100644 --- a/crates/erg_compiler/lib/core/_erg_std_prelude.py +++ b/crates/erg_compiler/lib/core/_erg_std_prelude.py @@ -1,5 +1,5 @@ # HACK: import MutType to suppress segfault in CPython 3.10 (cause unknown) -from _erg_array import Array, UnsizedArray +from _erg_list import List, UnsizedList from _erg_bool import Bool from _erg_bytes import Bytes from _erg_contains_operator import contains_operator diff --git a/crates/erg_compiler/lib/pystd/builtins.d.er b/crates/erg_compiler/lib/pystd/builtins.d.er index c7e022ffd..f1a253cb3 100644 --- a/crates/erg_compiler/lib/pystd/builtins.d.er +++ b/crates/erg_compiler/lib/pystd/builtins.d.er @@ -206,13 +206,13 @@ opened in a binary mode. ) => File! ''' -Convert `iterable` into an array. +Convert `iterable` into a list. ''' '''erg -assert array() == [] -assert array((1, 2)) == [1, 2] +assert list() == [] +assert list((1, 2)) == [1, 2] ''' -.array: |T| (iterable := Iterable(T)) -> [T; _] +.list: |T| (iterable := Iterable(T)) -> [T; _] ''' Convert `iterable` into a dict. diff --git a/crates/erg_compiler/lib/pystd/heapq.d.er b/crates/erg_compiler/lib/pystd/heapq.d.er index 99aa01973..1b5fe67e0 100644 --- a/crates/erg_compiler/lib/pystd/heapq.d.er +++ b/crates/erg_compiler/lib/pystd/heapq.d.er @@ -1,4 +1,4 @@ .heappush!: |T: Type|(heap: Iterable(T), item: T) => NoneType # TODO: Push! .heappop!: |T: Type|(heap: Iterable(T)) => T # TODO: Pop! .heappushpop!: |T: Type|(heap: Iterable(T), item: T) => T # TODO: Push! and Pop! -.heapify!: (heap: Array(Obj, _)) => NoneType +.heapify!: (heap: List(Obj, _)) => NoneType diff --git a/crates/erg_compiler/lib/pystd/sys.d.er b/crates/erg_compiler/lib/pystd/sys.d.er index 9444a7727..7aca3392d 100644 --- a/crates/erg_compiler/lib/pystd/sys.d.er +++ b/crates/erg_compiler/lib/pystd/sys.d.er @@ -56,7 +56,7 @@ io = pyimport "io" .seed_bits = Nat; .cutoff = Int; } -.path: Array!(Str, _) +.path: List!(Str, _) ''' * AIX -> 'aix' * FreeBSD -> 'freebsd' diff --git a/crates/erg_compiler/link_hir.rs b/crates/erg_compiler/link_hir.rs index 8d821e7e1..86f1c5a76 100644 --- a/crates/erg_compiler/link_hir.rs +++ b/crates/erg_compiler/link_hir.rs @@ -121,15 +121,15 @@ impl<'a> HIRLinker<'a> { } } } - Expr::Array(array) => match array { - Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter_mut() { + Expr::List(list) => match list { + List::Normal(lis) => { + for elem in lis.elems.pos_args.iter_mut() { Self::resolve_pymod_path(&mut elem.expr); } } - Array::WithLength(arr) => { - Self::resolve_pymod_path(&mut arr.elem); - if let Some(len) = arr.len.as_deref_mut() { + List::WithLength(lis) => { + Self::resolve_pymod_path(&mut lis.elem); + if let Some(len) = lis.len.as_deref_mut() { Self::resolve_pymod_path(len); } } @@ -245,15 +245,15 @@ impl<'a> HIRLinker<'a> { }, } } - Expr::Array(array) => match array { - Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter_mut() { + Expr::List(list) => match list { + List::Normal(lis) => { + for elem in lis.elems.pos_args.iter_mut() { self.replace_import(&mut elem.expr); } } - Array::WithLength(arr) => { - self.replace_import(&mut arr.elem); - if let Some(len) = arr.len.as_deref_mut() { + List::WithLength(lis) => { + self.replace_import(&mut lis.elem); + if let Some(len) = lis.len.as_deref_mut() { self.replace_import(len); } } diff --git a/crates/erg_compiler/lower.rs b/crates/erg_compiler/lower.rs index df44366c6..5779db4b4 100644 --- a/crates/erg_compiler/lower.rs +++ b/crates/erg_compiler/lower.rs @@ -33,8 +33,8 @@ use crate::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArti use crate::build_package::CheckStatus; use crate::module::SharedCompilerResource; use crate::ty::constructors::{ - array_t, free_var, func, guard, mono, poly, proc, refinement, set_t, singleton, ty_tp, - unsized_array_t, v_enum, + free_var, func, guard, list_t, mono, poly, proc, refinement, set_t, singleton, ty_tp, + unsized_list_t, v_enum, }; use crate::ty::free::Constraint; use crate::ty::typaram::TyParam; @@ -335,21 +335,19 @@ impl GenericASTLowerer { Ok(lit) } - fn lower_array(&mut self, array: ast::Array, expect: Option<&Type>) -> LowerResult { - log!(info "entered {}({array})", fn_name!()); - match array { - ast::Array::Normal(arr) => { - Ok(hir::Array::Normal(self.lower_normal_array(arr, expect)?)) - } - ast::Array::WithLength(arr) => Ok(hir::Array::WithLength( - self.lower_array_with_length(arr, expect)?, + fn lower_list(&mut self, list: ast::List, expect: Option<&Type>) -> LowerResult { + log!(info "entered {}({list})", fn_name!()); + match list { + ast::List::Normal(lis) => Ok(hir::List::Normal(self.lower_normal_list(lis, expect)?)), + ast::List::WithLength(lis) => Ok(hir::List::WithLength( + self.lower_list_with_length(lis, expect)?, )), other => feature_error!( LowerErrors, LowerError, self.module.context, other.loc(), - "array comprehension" + "list comprehension" ), } } @@ -364,10 +362,10 @@ impl GenericASTLowerer { elem.loc(), String::from(&self.module.context.name[..]), switch_lang!( - "japanese" => "配列の要素は全て同じ型である必要があります", + "japanese" => "リストの要素は全て同じ型である必要があります", "simplified_chinese" => "数组元素必须全部是相同类型", "traditional_chinese" => "數組元素必須全部是相同類型", - "english" => "all elements of an array must be of the same type", + "english" => "all elements of a list must be of the same type", ) .to_owned(), Some(switch_lang!( @@ -379,18 +377,18 @@ impl GenericASTLowerer { )) } - fn lower_normal_array( + fn lower_normal_list( &mut self, - array: ast::NormalArray, + list: ast::NormalList, expect: Option<&Type>, - ) -> LowerResult { - log!(info "entered {}({array})", fn_name!()); - let mut new_array = vec![]; - let eval_result = self.module.context.eval_const_normal_array(&array); - let (elems, ..) = array.elems.deconstruct(); + ) -> LowerResult { + log!(info "entered {}({list})", fn_name!()); + let mut new_list = vec![]; + let eval_result = self.module.context.eval_const_normal_list(&list); + let (elems, ..) = list.elems.deconstruct(); let expect_elem = expect.and_then(|t| { // REVIEW: are these all? - if !(t.is_array() || t.is_array_mut() || t.is_iterable()) { + if !(t.is_list() || t.is_list_mut() || t.is_iterable()) { return None; } self.module @@ -404,7 +402,7 @@ impl GenericASTLowerer { let union_ = self.module.context.union(&union, elem.ref_t()); self.homogeneity_check(expect_elem.as_ref(), &union_, &union, &elem)?; union = union_; - new_array.push(elem); + new_list.push(elem); } let elem_t = if union == Type::Never { free_var( @@ -414,14 +412,14 @@ impl GenericASTLowerer { } else { union }; - let elems = hir::Args::values(new_array, None); - let t = array_t(elem_t, TyParam::value(elems.len())); + let elems = hir::Args::values(new_list, None); + let t = list_t(elem_t, TyParam::value(elems.len())); let t = if let Ok(value) = eval_result { singleton(t, TyParam::Value(value)) } else { t }; - Ok(hir::NormalArray::new(array.l_sqbr, array.r_sqbr, t, elems)) + Ok(hir::NormalList::new(list.l_sqbr, list.r_sqbr, t, elems)) } fn homogeneity_check( @@ -466,14 +464,14 @@ impl GenericASTLowerer { Ok(()) } - fn lower_array_with_length( + fn lower_list_with_length( &mut self, - array: ast::ArrayWithLength, + list: ast::ListWithLength, expect: Option<&Type>, - ) -> LowerResult { - log!(info "entered {}({array})", fn_name!()); + ) -> LowerResult { + log!(info "entered {}({list})", fn_name!()); let expect_elem = expect.and_then(|t| { - if !(t.is_array() || t.is_array_mut() || t.is_iterable()) { + if !(t.is_list() || t.is_list_mut() || t.is_iterable()) { return None; } self.module @@ -481,26 +479,26 @@ impl GenericASTLowerer { .convert_tp_into_type(t.typarams().first()?.clone()) .ok() }); - let elem = self.lower_expr(array.elem.expr, expect_elem.as_ref())?; - let array_t = self.gen_array_with_length_type(&elem, &array.len); - let len = match *array.len { + let elem = self.lower_expr(list.elem.expr, expect_elem.as_ref())?; + let list_t = self.gen_list_with_length_type(&elem, &list.len); + let len = match *list.len { ast::Expr::Accessor(ast::Accessor::Ident(ident)) if ident.is_discarded() => None, len => Some(self.lower_expr(len, Some(&Type::Nat))?), }; - let hir_array = hir::ArrayWithLength::new(array.l_sqbr, array.r_sqbr, array_t, elem, len); - Ok(hir_array) + let hir_list = hir::ListWithLength::new(list.l_sqbr, list.r_sqbr, list_t, elem, len); + Ok(hir_list) } - fn gen_array_with_length_type(&self, elem: &hir::Expr, len: &ast::Expr) -> Type { + fn gen_list_with_length_type(&self, elem: &hir::Expr, len: &ast::Expr) -> Type { match len { ast::Expr::Accessor(ast::Accessor::Ident(ident)) if ident.is_discarded() => { - return unsized_array_t(elem.t()); + return unsized_list_t(elem.t()); } _ => {} } let maybe_len = self.module.context.eval_const_expr(len); match maybe_len { - Ok(v @ ValueObj::Nat(_)) => array_t(elem.t(), TyParam::Value(v)), + Ok(v @ ValueObj::Nat(_)) => list_t(elem.t(), TyParam::Value(v)), Ok(other) => todo!("{other} is not a Nat object"), Err(err) => todo!("{err}"), } @@ -2947,7 +2945,7 @@ impl GenericASTLowerer { let casted = self.module.context.get_casted_type(&expr); let mut expr = match expr { ast::Expr::Literal(lit) => hir::Expr::Literal(self.lower_literal(lit, expect)?), - ast::Expr::Array(arr) => hir::Expr::Array(self.lower_array(arr, expect)?), + ast::Expr::List(lis) => hir::Expr::List(self.lower_list(lis, expect)?), ast::Expr::Tuple(tup) => hir::Expr::Tuple(self.lower_tuple(tup, expect)?), ast::Expr::Record(rec) => hir::Expr::Record(self.lower_record(rec, expect)?), ast::Expr::Set(set) => hir::Expr::Set(self.lower_set(set, expect)?), diff --git a/crates/erg_compiler/ownercheck.rs b/crates/erg_compiler/ownercheck.rs index 34e22c8d2..2ec08c0ff 100644 --- a/crates/erg_compiler/ownercheck.rs +++ b/crates/erg_compiler/ownercheck.rs @@ -13,7 +13,7 @@ use erg_parser::ast::{ParamPattern, VarName}; use crate::ty::{HasType, Ownership, Visibility}; use crate::error::{OwnershipError, OwnershipErrors}; -use crate::hir::{self, Accessor, Array, Block, Def, Expr, Identifier, Signature, Tuple, HIR}; +use crate::hir::{self, Accessor, Block, Def, Expr, Identifier, List, Signature, Tuple, HIR}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum WrapperKind { @@ -222,23 +222,23 @@ impl OwnershipChecker { Expr::UnaryOp(unary) => { self.check_expr(&unary.expr, ownership, false); } - Expr::Array(array) => match array { - Array::Normal(arr) => { - for a in arr.elems.pos_args.iter() { + Expr::List(list) => match list { + List::Normal(lis) => { + for a in lis.elems.pos_args.iter() { self.check_expr(&a.expr, ownership, false); } } - Array::WithLength(arr) => { - self.check_expr(&arr.elem, ownership, false); - if let Some(len) = &arr.len { + List::WithLength(lis) => { + self.check_expr(&lis.elem, ownership, false); + if let Some(len) = &lis.len { self.check_expr(len, ownership, false); } } _ => todo!(), }, Expr::Tuple(tuple) => match tuple { - Tuple::Normal(arr) => { - for a in arr.elems.pos_args.iter() { + Tuple::Normal(lis) => { + for a in lis.elems.pos_args.iter() { self.check_expr(&a.expr, ownership, false); } } diff --git a/crates/erg_compiler/tests/infer.er b/crates/erg_compiler/tests/infer.er index 88c3e21c0..be2d36a5a 100644 --- a/crates/erg_compiler/tests/infer.er +++ b/crates/erg_compiler/tests/infer.er @@ -40,4 +40,4 @@ val!() = val = val!() xs as [Nat or Str; _] = [1, 2, "aa"] -ys = array filter x -> x in Int, xs +ys = list filter x -> x in Int, xs diff --git a/crates/erg_compiler/tests/test.rs b/crates/erg_compiler/tests/test.rs index 9a1d01c45..b7434ac34 100644 --- a/crates/erg_compiler/tests/test.rs +++ b/crates/erg_compiler/tests/test.rs @@ -12,8 +12,8 @@ use erg_compiler::error::CompileErrors; use erg_compiler::lower::ASTLowerer; use erg_compiler::ty::constructors::{ - array_t, func0, func1, func2, kw, mono, nd_func, nd_proc, or, poly, proc1, subtype_q, ty_tp, - type_q, unknown_len_array_mut, unknown_len_array_t, v_enum, + func0, func1, func2, kw, list_t, mono, nd_func, nd_proc, or, poly, proc1, subtype_q, ty_tp, + type_q, unknown_len_list_mut, unknown_len_list_t, v_enum, }; use erg_compiler::ty::Type::*; @@ -71,15 +71,15 @@ fn _test_infer_types() -> Result<(), ()> { module.context.assert_var_type("abs2", &abs_t)?; let norm_t = func1(mono("::Norm"), Nat); module.context.assert_var_type("norm", &norm_t)?; - let a_t = array_t( + let a_t = list_t( v_enum(set! {1.into(), 2.into(), 3.into(), 4.into()}), 4.into(), ); module.context.assert_var_type("a", &a_t)?; - let abc_t = unknown_len_array_t(v_enum(set! {"a".into(), "b".into(), "c".into()})); + let abc_t = unknown_len_list_t(v_enum(set! {"a".into(), "b".into(), "c".into()})); module.context.assert_var_type("abc", &abc_t)?; let t = type_q("T"); - let f_t = proc1(t.clone(), unknown_len_array_mut(t)).quantify(); + let f_t = proc1(t.clone(), unknown_len_list_mut(t)).quantify(); module.context.assert_var_type("f!", &f_t)?; let r = type_q("R"); let add_r = poly("Add", vec![ty_tp(r.clone())]); @@ -92,7 +92,7 @@ fn _test_infer_types() -> Result<(), ()> { .assert_var_type("val", &v_enum(set! { "b".into(), "d".into() }))?; module .context - .assert_var_type("ys", &unknown_len_array_t(Nat))?; + .assert_var_type("ys", &unknown_len_list_t(Nat))?; Ok(()) } diff --git a/crates/erg_compiler/transpile.rs b/crates/erg_compiler/transpile.rs index af8c58b85..3e4087b38 100644 --- a/crates/erg_compiler/transpile.rs +++ b/crates/erg_compiler/transpile.rs @@ -23,7 +23,7 @@ use crate::context::{Context, ContextProvider, ModuleContext}; use crate::desugar_hir::HIRDesugarer; use crate::error::{CompileError, CompileErrors, CompileResult}; use crate::hir::{ - Accessor, Args, Array, BinOp, Block, Call, ClassDef, Def, Dict, Expr, Identifier, Lambda, + Accessor, Args, BinOp, Block, Call, ClassDef, Def, Dict, Expr, Identifier, Lambda, List, Literal, Params, PatchDef, ReDef, Record, Set, Signature, Tuple, UnaryOp, HIR, }; use crate::link_hir::HIRLinker; @@ -476,7 +476,7 @@ impl PyScriptGenerator { .replace("from _erg_str import Str", "") .replace("from _erg_float import FloatMut", "") .replace("from _erg_float import Float", "") - .replace("from _erg_array import Array", "") + .replace("from _erg_list import List", "") .replace("from _erg_range import Range", "") .replace("from _erg_result import Error", "") .replace("from _erg_result import is_ok", "") @@ -531,7 +531,7 @@ impl PyScriptGenerator { self.load_contains_op_if_not(); if self.range_ops_loaded { self.prelude += &Self::replace_import(include_str!("lib/core/_erg_float.py")); - self.prelude += &Self::replace_import(include_str!("lib/core/_erg_array.py")); + self.prelude += &Self::replace_import(include_str!("lib/core/_erg_list.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_dict.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_set.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_bytes.py")); @@ -541,7 +541,7 @@ impl PyScriptGenerator { self.prelude += &Self::replace_import(include_str!("lib/core/_erg_bool.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_str.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_float.py")); - self.prelude += &Self::replace_import(include_str!("lib/core/_erg_array.py")); + self.prelude += &Self::replace_import(include_str!("lib/core/_erg_list.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_dict.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_set.py")); self.prelude += &Self::replace_import(include_str!("lib/core/_erg_bytes.py")); @@ -578,11 +578,11 @@ impl PyScriptGenerator { Expr::Call(call) => self.transpile_call(call), Expr::BinOp(bin) => self.transpile_binop(bin), Expr::UnaryOp(unary) => self.transpile_unaryop(unary), - Expr::Array(array) => match array { - Array::Normal(arr) => { + Expr::List(list) => match list { + List::Normal(lis) => { self.load_builtin_types_if_not(); - let mut code = "Array([".to_string(); - for elem in arr.elems.pos_args { + let mut code = "List([".to_string(); + for elem in lis.elems.pos_args { code += &format!("{},", self.transpile_expr(elem.expr)); } code += "])"; @@ -762,7 +762,7 @@ impl PyScriptGenerator { prefix.push('('); } other => { - if let t @ ("Bytes" | "Array" | "Dict" | "Set") = &other.qual_name()[..] { + if let t @ ("Bytes" | "List" | "Dict" | "Set") = &other.qual_name()[..] { self.load_builtin_types_if_not(); prefix.push_str(t); prefix.push('('); @@ -773,9 +773,9 @@ impl PyScriptGenerator { match acc { Accessor::Ident(ident) => { match &ident.inspect()[..] { - "Str" | "Bytes" | "Bool" | "Nat" | "Int" | "Float" | "Array" | "Dict" + "Str" | "Bytes" | "Bool" | "Nat" | "Int" | "Float" | "List" | "Dict" | "Set" | "Str!" | "Bytes!" | "Bool!" | "Nat!" | "Int!" | "Float!" - | "Array!" => { + | "List!" => { self.load_builtin_types_if_not(); } "if" | "if!" | "for!" | "while" | "discard" => { @@ -1288,24 +1288,24 @@ impl JsonGenerator { fn expr_into_value(&self, expr: Expr) -> Option { match expr { - Expr::Array(Array::Normal(arr)) => { + Expr::List(List::Normal(lis)) => { let mut vals = vec![]; - for elem in arr.elems.pos_args { + for elem in lis.elems.pos_args { if let Some(val) = self.expr_into_value(elem.expr) { vals.push(val); } else { return None; } } - Some(ValueObj::Array(vals.into())) + Some(ValueObj::List(vals.into())) } - Expr::Array(Array::WithLength(arr)) => { - let len = arr + Expr::List(List::WithLength(lis)) => { + let len = lis .len .and_then(|len| self.expr_into_value(*len)) .and_then(|v| usize::try_from(&v).ok())?; - let vals = vec![self.expr_into_value(*arr.elem)?; len]; - Some(ValueObj::Array(vals.into())) + let vals = vec![self.expr_into_value(*lis.elem)?; len]; + Some(ValueObj::List(vals.into())) } Expr::Tuple(Tuple::Normal(tup)) => { let mut vals = vec![]; @@ -1379,10 +1379,10 @@ impl JsonGenerator { replace_non_symbolic(&acc.to_string()) } } - Expr::Array(array) => match array { - Array::Normal(arr) => { + Expr::List(list) => match list { + List::Normal(lis) => { let mut code = "[".to_string(); - for (i, elem) in arr.elems.pos_args.into_iter().enumerate() { + for (i, elem) in lis.elems.pos_args.into_iter().enumerate() { if i > 0 { code += ", "; } diff --git a/crates/erg_compiler/ty/constructors.rs b/crates/erg_compiler/ty/constructors.rs index 3f73c9642..74fb68253 100644 --- a/crates/erg_compiler/ty/constructors.rs +++ b/crates/erg_compiler/ty/constructors.rs @@ -44,36 +44,36 @@ pub fn named_uninit_var(name: Str) -> Type { Type::FreeVar(Free::new_named_unbound(name, 1, Constraint::Uninited)) } -pub fn array_t(elem_t: Type, len: TyParam) -> Type { - poly("Array", vec![TyParam::t(elem_t), len]) +pub fn list_t(elem_t: Type, len: TyParam) -> Type { + poly("List", vec![TyParam::t(elem_t), len]) } -pub fn array_mut(elem_t: Type, len: TyParam) -> Type { - poly("Array!", vec![TyParam::t(elem_t), len]) +pub fn list_mut(elem_t: Type, len: TyParam) -> Type { + poly("List!", vec![TyParam::t(elem_t), len]) } -pub fn unknown_len_array_t(elem_t: Type) -> Type { - array_t(elem_t, TyParam::erased(Type::Nat)) +pub fn unknown_len_list_t(elem_t: Type) -> Type { + list_t(elem_t, TyParam::erased(Type::Nat)) } -pub fn unknown_len_array_mut(elem_t: Type) -> Type { - array_mut(elem_t, TyParam::erased(Type::Nat)) +pub fn unknown_len_list_mut(elem_t: Type) -> Type { + list_mut(elem_t, TyParam::erased(Type::Nat)) } pub fn str_dict_t(value: Type) -> Type { dict! { Type::Str => value }.into() } -/// `UnsizedArray` is a type of `[x; _]` (unsized array literal). -/// `UnsizedArray(T) != Array(T, _)` -pub fn unsized_array_t(elem_t: Type) -> Type { - poly("UnsizedArray", vec![TyParam::t(elem_t)]) +/// `UnsizedList` is a type of `[x; _]` (unsized list literal). +/// `UnsizedList(T) != List(T, _)` +pub fn unsized_list_t(elem_t: Type) -> Type { + poly("UnsizedList", vec![TyParam::t(elem_t)]) } pub fn tuple_t(args: Vec) -> Type { poly( "Tuple", - vec![TyParam::Array(args.into_iter().map(TyParam::t).collect())], + vec![TyParam::List(args.into_iter().map(TyParam::t).collect())], ) } diff --git a/crates/erg_compiler/ty/deserialize.rs b/crates/erg_compiler/ty/deserialize.rs index 488cb74a9..88f86cd4f 100644 --- a/crates/erg_compiler/ty/deserialize.rs +++ b/crates/erg_compiler/ty/deserialize.rs @@ -12,7 +12,7 @@ use erg_common::{fn_name, switch_lang}; use erg_common::{ArcArray, Str}; use super::codeobj::{CodeObj, FastKind}; -use super::constructors::array_t; +use super::constructors::list_t; use super::typaram::TyParam; use super::value::ValueObj; use super::{HasType, Type}; @@ -140,7 +140,7 @@ impl Deserializer { } fn get_cached_arr(&mut self, arr: &[ValueObj]) -> ValueObj { - ValueObj::Array(self.arr_cache.get(arr)) + ValueObj::List(self.arr_cache.get(arr)) } pub fn vec_to_bytes(vector: Vec) -> [u8; LEN] { @@ -226,7 +226,7 @@ impl Deserializer { field: Option<&str>, ) -> DeserializeResult> { match self.deserialize_const(v, python_ver)? { - ValueObj::Array(arr) => Ok(arr.to_vec()), + ValueObj::List(lis) => Ok(lis.to_vec()), other => Err(DeserializeError::type_error( field, &Type::Str, @@ -242,7 +242,7 @@ impl Deserializer { field: Option<&str>, ) -> DeserializeResult> { match self.deserialize_const(v, python_ver)? { - ValueObj::Array(arr) => Ok(arr), + ValueObj::List(lis) => Ok(lis), other => Err(DeserializeError::type_error( field, &Type::Str, @@ -273,16 +273,16 @@ impl Deserializer { field: Option<&str>, ) -> DeserializeResult> { match self.deserialize_const(v, python_ver)? { - ValueObj::Array(arr) | ValueObj::Tuple(arr) => { - let mut strs = Vec::with_capacity(arr.len()); - for c in arr.iter().cloned() { + ValueObj::List(lis) | ValueObj::Tuple(lis) => { + let mut strs = Vec::with_capacity(lis.len()); + for c in lis.iter().cloned() { strs.push(self.try_into_str(c)?); } Ok(strs) } other => Err(DeserializeError::type_error( field, - &array_t(Type::Str, TyParam::erased(Type::Nat)), + &list_t(Type::Str, TyParam::erased(Type::Nat)), &other.class(), )), } diff --git a/crates/erg_compiler/ty/mod.rs b/crates/erg_compiler/ty/mod.rs index fb7aa21eb..2f89230d3 100644 --- a/crates/erg_compiler/ty/mod.rs +++ b/crates/erg_compiler/ty/mod.rs @@ -2040,8 +2040,8 @@ impl Type { _ => None, }, Self::Poly { name, params } => match &name[..] { - "Array!" => Some(Self::Poly { - name: "Array".into(), + "List!" => Some(Self::Poly { + name: "List".into(), params: params.clone(), }), "Set!" => Some(Self::Poly { @@ -2106,13 +2106,13 @@ impl Type { } } - /// value class := mono value object class | (Array | Set)(value class) + /// value class := mono value object class | (List | Set)(value class) pub fn is_value_class(&self) -> bool { match self { Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_value_class(), Self::Refinement(refine) => refine.t.is_value_class(), Self::Poly { name, params } => { - if &name[..] == "Array" || &name[..] == "Set" { + if &name[..] == "List" || &name[..] == "Set" { let Some(elem_t) = params.first().and_then(|p| <&Type>::try_from(p).ok()) else { if DEBUG_MODE { @@ -2195,7 +2195,7 @@ impl Type { Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_singleton(), Self::Refinement(refine) => refine.t.is_singleton(), Self::Poly { name, params } => { - if &name[..] == "Array" || &name[..] == "Set" { + if &name[..] == "List" || &name[..] == "Set" { let Some(elem_t) = params.first().and_then(|p| <&Type>::try_from(p).ok()) else { if DEBUG_MODE { @@ -2373,11 +2373,11 @@ impl Type { } } - pub fn is_array(&self) -> bool { + pub fn is_list(&self) -> bool { match self { - Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_array(), - Self::Poly { name, .. } => &name[..] == "Array", - Self::Refinement(refine) => refine.t.is_array(), + Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_list(), + Self::Poly { name, .. } => &name[..] == "List", + Self::Refinement(refine) => refine.t.is_list(), _ => false, } } @@ -2391,11 +2391,11 @@ impl Type { } } - pub fn is_array_mut(&self) -> bool { + pub fn is_list_mut(&self) -> bool { match self { - Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_array_mut(), - Self::Poly { name, .. } => &name[..] == "Array!", - Self::Refinement(refine) => refine.t.is_array_mut(), + Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_list_mut(), + Self::Poly { name, .. } => &name[..] == "List!", + Self::Refinement(refine) => refine.t.is_list_mut(), _ => false, } } @@ -3391,7 +3391,7 @@ impl Type { match self { Self::FreeVar(fv) if fv.is_linked() => fv.crack().container_len(), Self::Poly { name, params } => match &name[..] { - "Array" => { + "List" => { if let TyParam::Value(ValueObj::Nat(n)) = ¶ms[0] { Some(*n as usize) } else { @@ -3691,7 +3691,7 @@ impl Type { /// ```erg /// (Failure -> Int).replace_failure() == (Obj -> Int) /// (Int -> Failure).replace_failure() == (Int -> Never) - /// Array(Failure, 3).replace_failure() == Array(Never, 3) + /// List(Failure, 3).replace_failure() == List(Never, 3) /// ``` pub fn replace_failure(&self) -> Type { match self { @@ -4093,7 +4093,7 @@ impl Type { /// ```erg /// Int.contained_ts() == {Int} - /// Array(Array(Int)).contained_ts() == {Array(Int), Int} + /// List(List(Int)).contained_ts() == {List(Int), Int} /// (Int or Str).contained_ts() == {Int, Str} /// ``` pub fn contained_ts(&self) -> Set { @@ -4460,8 +4460,8 @@ pub enum TypeCode { Bool, Str, StrMut, - Array, // 要素数は検査済みなので、気にする必要はない - ArrayMut, + List, // 要素数は検査済みなので、気にする必要はない + ListMut, // Dict, Set, SetMut, @@ -4493,7 +4493,7 @@ impl From<&Type> for TypeCode { _ => Self::Other, }, Type::Poly { name, .. } => match &name[..] { - "Array" | "Array!" => Self::Array, + "List" | "List!" => Self::List, "Set" | "Set!" => Self::Set, "Func" => Self::Func, "Proc" => Self::Proc, @@ -4516,7 +4516,7 @@ pub enum TypePair { IntFloat, IntStr, IntBool, - IntArray, + IntList, IntFunc, IntProc, NatInt, @@ -4524,7 +4524,7 @@ pub enum TypePair { NatFloat, NatStr, NatBool, - NatArray, + NatList, NatFunc, NatProc, FloatInt, @@ -4532,7 +4532,7 @@ pub enum TypePair { FloatFloat, FloatStr, FloatBool, - FloatArray, + FloatList, FloatFunc, FloatProc, BoolInt, @@ -4540,7 +4540,7 @@ pub enum TypePair { BoolFloat, BoolStr, BoolBool, - BoolArray, + BoolList, BoolFunc, BoolProc, StrInt, @@ -4548,24 +4548,24 @@ pub enum TypePair { StrFloat, StrBool, StrStr, - StrArray, + StrList, StrFunc, StrProc, // 要素数は検査済みなので、気にする必要はない - ArrayInt, - ArrayNat, - ArrayFloat, - ArrayStr, - ArrayBool, - ArrayArray, - ArrayFunc, - ArrayProc, + ListInt, + ListNat, + ListFloat, + ListStr, + ListBool, + ListList, + ListFunc, + ListProc, FuncInt, FuncNat, FuncFloat, FuncStr, FuncBool, - FuncArray, + FuncList, FuncFunc, FuncProc, ProcInt, @@ -4573,7 +4573,7 @@ pub enum TypePair { ProcFloat, ProcStr, ProcBool, - ProcArray, + ProcList, ProcFunc, ProcProc, Others, @@ -4588,7 +4588,7 @@ impl From for TypePair { 3 => Self::IntFloat, 4 => Self::IntStr, 5 => Self::IntBool, - 6 => Self::IntArray, + 6 => Self::IntList, 7 => Self::IntFunc, 8 => Self::IntProc, 9 => Self::NatInt, @@ -4596,7 +4596,7 @@ impl From for TypePair { 11 => Self::NatFloat, 12 => Self::NatStr, 13 => Self::NatBool, - 14 => Self::NatArray, + 14 => Self::NatList, 15 => Self::NatFunc, 16 => Self::NatProc, 17 => Self::FloatInt, @@ -4604,7 +4604,7 @@ impl From for TypePair { 19 => Self::FloatFloat, 20 => Self::FloatStr, 21 => Self::FloatBool, - 22 => Self::FloatArray, + 22 => Self::FloatList, 23 => Self::FloatFunc, 24 => Self::FloatProc, 25 => Self::BoolInt, @@ -4612,7 +4612,7 @@ impl From for TypePair { 27 => Self::BoolFloat, 28 => Self::BoolStr, 29 => Self::BoolBool, - 30 => Self::BoolArray, + 30 => Self::BoolList, 31 => Self::BoolFunc, 32 => Self::BoolProc, 33 => Self::StrInt, @@ -4620,24 +4620,24 @@ impl From for TypePair { 35 => Self::StrFloat, 36 => Self::StrBool, 37 => Self::StrStr, - 38 => Self::StrArray, + 38 => Self::StrList, 39 => Self::StrFunc, 40 => Self::StrProc, // 要素数は検査済みなので、気にする必要はない - 41 => Self::ArrayInt, - 42 => Self::ArrayNat, - 43 => Self::ArrayFloat, - 44 => Self::ArrayStr, - 45 => Self::ArrayBool, - 46 => Self::ArrayArray, - 47 => Self::ArrayFunc, - 48 => Self::ArrayProc, + 41 => Self::ListInt, + 42 => Self::ListNat, + 43 => Self::ListFloat, + 44 => Self::ListStr, + 45 => Self::ListBool, + 46 => Self::ListList, + 47 => Self::ListFunc, + 48 => Self::ListProc, 49 => Self::FuncInt, 50 => Self::FuncNat, 51 => Self::FuncFloat, 52 => Self::FuncStr, 53 => Self::FuncBool, - 54 => Self::FuncArray, + 54 => Self::FuncList, 55 => Self::FuncFunc, 56 => Self::FuncProc, 57 => Self::ProcInt, @@ -4645,7 +4645,7 @@ impl From for TypePair { 59 => Self::ProcFloat, 60 => Self::ProcStr, 61 => Self::ProcBool, - 62 => Self::ProcArray, + 62 => Self::ProcList, 63 => Self::ProcProc, 64 => Self::Others, _ => Self::Illegals, @@ -4662,7 +4662,7 @@ impl TypePair { (Type::Int, Type::Float) => Self::IntFloat, (Type::Int, Type::Str) => Self::IntStr, (Type::Int, Type::Bool) => Self::IntBool, - (Type::Int, Type::Poly { name, .. }) if &name[..] == "Array" => Self::IntArray, + (Type::Int, Type::Poly { name, .. }) if &name[..] == "List" => Self::IntList, (Type::Int, Type::Poly { name, .. }) if &name[..] == "Func" => Self::IntFunc, (Type::Int, Type::Poly { name, .. }) if &name[..] == "Proc" => Self::IntProc, (Type::Nat, Type::Int) => Self::NatInt, @@ -4670,7 +4670,7 @@ impl TypePair { (Type::Nat, Type::Float) => Self::NatFloat, (Type::Nat, Type::Str) => Self::NatStr, (Type::Nat, Type::Bool) => Self::NatBool, - (Type::Nat, Type::Poly { name, .. }) if &name[..] == "Array" => Self::NatArray, + (Type::Nat, Type::Poly { name, .. }) if &name[..] == "List" => Self::NatList, (Type::Nat, Type::Poly { name, .. }) if &name[..] == "Func" => Self::NatFunc, (Type::Nat, Type::Poly { name, .. }) if &name[..] == "Proc" => Self::NatProc, (Type::Float, Type::Int) => Self::FloatInt, @@ -4678,7 +4678,7 @@ impl TypePair { (Type::Float, Type::Float) => Self::FloatFloat, (Type::Float, Type::Str) => Self::FloatStr, (Type::Float, Type::Bool) => Self::FloatBool, - (Type::Float, Type::Poly { name, .. }) if &name[..] == "Array" => Self::FloatArray, + (Type::Float, Type::Poly { name, .. }) if &name[..] == "List" => Self::FloatList, (Type::Float, Type::Poly { name, .. }) if &name[..] == "Func" => Self::FloatFunc, (Type::Float, Type::Poly { name, .. }) if &name[..] == "Proc" => Self::FloatProc, (Type::Bool, Type::Int) => Self::BoolInt, @@ -4686,7 +4686,7 @@ impl TypePair { (Type::Bool, Type::Float) => Self::BoolFloat, (Type::Bool, Type::Str) => Self::BoolStr, (Type::Bool, Type::Bool) => Self::BoolBool, - (Type::Bool, Type::Poly { name, .. }) if &name[..] == "Array" => Self::BoolArray, + (Type::Bool, Type::Poly { name, .. }) if &name[..] == "List" => Self::BoolList, (Type::Bool, Type::Poly { name, .. }) if &name[..] == "Func" => Self::BoolFunc, (Type::Bool, Type::Poly { name, .. }) if &name[..] == "Proc" => Self::BoolProc, (Type::Str, Type::Int) => Self::StrInt, @@ -4694,29 +4694,29 @@ impl TypePair { (Type::Str, Type::Float) => Self::StrFloat, (Type::Str, Type::Bool) => Self::StrBool, (Type::Str, Type::Str) => Self::StrStr, - (Type::Str, Type::Poly { name, .. }) if &name[..] == "Array" => Self::StrArray, + (Type::Str, Type::Poly { name, .. }) if &name[..] == "List" => Self::StrList, (Type::Str, Type::Poly { name, .. }) if &name[..] == "Func" => Self::StrFunc, (Type::Str, Type::Poly { name, .. }) if &name[..] == "Proc" => Self::StrProc, // 要素数は検査済みなので、気にする必要はない - (Type::Poly { name, .. }, Type::Int) if &name[..] == "Array" => Self::ArrayInt, - (Type::Poly { name, .. }, Type::Nat) if &name[..] == "Array" => Self::ArrayNat, - (Type::Poly { name, .. }, Type::Float) if &name[..] == "Array" => Self::ArrayFloat, - (Type::Poly { name, .. }, Type::Str) if &name[..] == "Array" => Self::ArrayStr, - (Type::Poly { name, .. }, Type::Bool) if &name[..] == "Array" => Self::ArrayBool, + (Type::Poly { name, .. }, Type::Int) if &name[..] == "List" => Self::ListInt, + (Type::Poly { name, .. }, Type::Nat) if &name[..] == "List" => Self::ListNat, + (Type::Poly { name, .. }, Type::Float) if &name[..] == "List" => Self::ListFloat, + (Type::Poly { name, .. }, Type::Str) if &name[..] == "List" => Self::ListStr, + (Type::Poly { name, .. }, Type::Bool) if &name[..] == "List" => Self::ListBool, (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) - if &ln[..] == "Array" && &rn[..] == "Array" => + if &ln[..] == "List" && &rn[..] == "List" => { - Self::ArrayArray + Self::ListList } (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) - if &ln[..] == "Array" && &rn[..] == "Func" => + if &ln[..] == "List" && &rn[..] == "Func" => { - Self::ArrayFunc + Self::ListFunc } (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) - if &ln[..] == "Array" && &rn[..] == "Proc" => + if &ln[..] == "List" && &rn[..] == "Proc" => { - Self::ArrayProc + Self::ListProc } (Type::Poly { name, .. }, Type::Int) if &name[..] == "Func" => Self::FuncInt, (Type::Poly { name, .. }, Type::Nat) if &name[..] == "Func" => Self::FuncNat, @@ -4724,9 +4724,9 @@ impl TypePair { (Type::Poly { name, .. }, Type::Str) if &name[..] == "Func" => Self::FuncStr, (Type::Poly { name, .. }, Type::Bool) if &name[..] == "Func" => Self::FuncBool, (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) - if &ln[..] == "Func" && &rn[..] == "Array" => + if &ln[..] == "Func" && &rn[..] == "List" => { - Self::FuncArray + Self::FuncList } (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) if &ln[..] == "Func" && &rn[..] == "Func" => @@ -4744,9 +4744,9 @@ impl TypePair { (Type::Poly { name, .. }, Type::Str) if &name[..] == "Proc" => Self::ProcStr, (Type::Poly { name, .. }, Type::Bool) if &name[..] == "Proc" => Self::ProcBool, (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) - if &ln[..] == "Proc" && &rn[..] == "Array" => + if &ln[..] == "Proc" && &rn[..] == "List" => { - Self::ProcArray + Self::ProcList } (Type::Poly { name: ln, .. }, Type::Poly { name: rn, .. }) if &ln[..] == "Proc" && &rn[..] == "Func" => diff --git a/crates/erg_compiler/ty/typaram.rs b/crates/erg_compiler/ty/typaram.rs index 6170a40a9..61690eaf7 100644 --- a/crates/erg_compiler/ty/typaram.rs +++ b/crates/erg_compiler/ty/typaram.rs @@ -240,9 +240,9 @@ impl TyParamLambda { /// * Type: Int, Add(?R, ?O), ... /// * Mono: I, N, ... /// * Attr: math.PI, ... -/// * Array: `[1, 2, N]` +/// * List: `[1, 2, N]` /// * Tuple: (1, N, True) -/// * App: Array(Int), Fib(10), ... +/// * App: List(Int), Fib(10), ... /// * QuantVar: N: Nat, ... /// * FreeVar: ?I: Int, ... /// * UnaryOp: -N, ~B, ... @@ -252,8 +252,8 @@ impl TyParamLambda { pub enum TyParam { Value(ValueObj), Type(Box), - Array(Vec), - UnsizedArray(Box), + List(Vec), + UnsizedList(Box), Tuple(Vec), Set(Set), Dict(Dict), @@ -296,8 +296,8 @@ impl PartialEq for TyParam { match (self, other) { (Self::Value(l), Self::Value(r)) => l == r, (Self::Type(l), Self::Type(r)) => l == r, - (Self::Array(l), Self::Array(r)) => l == r, - (Self::UnsizedArray(l), Self::UnsizedArray(r)) => l == r, + (Self::List(l), Self::List(r)) => l == r, + (Self::UnsizedList(l), Self::UnsizedList(r)) => l == r, (Self::Tuple(l), Self::Tuple(r)) => l == r, (Self::Dict(l), Self::Dict(r)) => l == r, (Self::Record(l), Self::Record(r)) => l == r, @@ -435,9 +435,9 @@ impl LimitedDisplay for TyParam { write!(f, ")")?; Ok(()) } - Self::Array(arr) => { + Self::List(lis) => { write!(f, "[")?; - for (i, t) in arr.iter().enumerate() { + for (i, t) in lis.iter().enumerate() { if i > 0 { write!(f, ", ")?; } @@ -449,7 +449,7 @@ impl LimitedDisplay for TyParam { } write!(f, "]") } - Self::UnsizedArray(elem) => { + Self::UnsizedList(elem) => { write!(f, "[")?; elem.limited_fmt(f, limit - 1)?; write!(f, "; _]") @@ -685,16 +685,16 @@ impl TryFrom for ValueObj { type Error = (); fn try_from(tp: TyParam) -> Result { match tp { - TyParam::Array(tps) => { + TyParam::List(tps) => { let mut vals = vec![]; for tp in tps { vals.push(ValueObj::try_from(tp)?); } - Ok(ValueObj::Array(Arc::from(vals))) + Ok(ValueObj::List(Arc::from(vals))) } - TyParam::UnsizedArray(elem) => { + TyParam::UnsizedList(elem) => { let elem = ValueObj::try_from(*elem)?; - Ok(ValueObj::UnsizedArray(Box::new(elem))) + Ok(ValueObj::UnsizedList(Box::new(elem))) } TyParam::Tuple(tps) => { let mut vals = vec![]; @@ -768,7 +768,7 @@ impl TryFrom for Vec { fn try_from(tp: TyParam) -> Result { match tp { TyParam::FreeVar(fv) if fv.is_linked() => Vec::try_from(fv.crack().clone()), - TyParam::Array(tps) => Ok(tps), + TyParam::List(tps) => Ok(tps), _ => Err(()), } } @@ -783,7 +783,7 @@ impl<'a> TryFrom<&'a TyParam> for &'a Type { } TyParam::Type(t) => Ok(t.as_ref()), TyParam::Value(v) => <&Type>::try_from(v), - // TODO: Array, Dict, Set + // TODO: List, Dict, Set _ => Err(()), } } @@ -805,7 +805,7 @@ impl HasLevel for TyParam { match self { Self::Type(t) => t.level(), Self::FreeVar(fv) => fv.level(), - Self::Array(tps) | Self::Tuple(tps) => tps.iter().filter_map(|tp| tp.level()).min(), + Self::List(tps) | Self::Tuple(tps) => tps.iter().filter_map(|tp| tp.level()).min(), Self::Dict(tps) => tps .iter() .map(|(k, v)| { @@ -844,7 +844,7 @@ impl HasLevel for TyParam { v.set_level(level); } } - Self::Array(tps) => { + Self::List(tps) => { for tp in tps { tp.set_level(level); } @@ -883,7 +883,7 @@ impl StructuralEq for TyParam { fn structural_eq(&self, other: &Self) -> bool { match (self, other) { (Self::Type(l), Self::Type(r)) => l.structural_eq(r), - (Self::Array(l), Self::Array(r)) => l.iter().zip(r).all(|(l, r)| l.structural_eq(r)), + (Self::List(l), Self::List(r)) => l.iter().zip(r).all(|(l, r)| l.structural_eq(r)), (Self::Tuple(l), Self::Tuple(r)) => l.iter().zip(r).all(|(l, r)| l.structural_eq(r)), (Self::Dict(l), Self::Dict(r)) => { if l.len() != r.len() { @@ -1076,8 +1076,8 @@ impl TyParam { Self::Erased(Box::new(t)) } - pub fn unsized_array(elem: TyParam) -> Self { - Self::UnsizedArray(Box::new(elem)) + pub fn unsized_list(elem: TyParam) -> Self { + Self::UnsizedList(Box::new(elem)) } // if self: Ratio, Succ(self) => self+ε @@ -1196,7 +1196,7 @@ impl TyParam { } Self::Type(t) => t.qvars(), Self::Proj { obj, .. } => obj.qvars(), - Self::Array(ts) | Self::Tuple(ts) => { + Self::List(ts) | Self::Tuple(ts) => { ts.iter().fold(set! {}, |acc, t| acc.concat(t.qvars())) } Self::Set(ts) => ts.iter().fold(set! {}, |acc, t| acc.concat(t.qvars())), @@ -1225,7 +1225,7 @@ impl TyParam { Self::FreeVar(fv) if fv.is_linked() => fv.crack().has_qvar(), Self::Type(t) => t.has_qvar(), Self::Proj { obj, .. } => obj.has_qvar(), - Self::Array(tps) | Self::Tuple(tps) => tps.iter().any(|tp| tp.has_qvar()), + Self::List(tps) | Self::Tuple(tps) => tps.iter().any(|tp| tp.has_qvar()), Self::Set(tps) => tps.iter().any(|tp| tp.has_qvar()), Self::Dict(tps) => tps.iter().any(|(k, v)| k.has_qvar() || v.has_qvar()), Self::Record(rec) | Self::DataClass { fields: rec, .. } => { @@ -1247,7 +1247,7 @@ impl TyParam { Self::Type(t) => t.contains_tvar(target), Self::Erased(t) => t.contains_tvar(target), Self::Proj { obj, .. } => obj.contains_tvar(target), - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tvar(target)), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tvar(target)), Self::Set(ts) => ts.iter().any(|t| t.contains_tvar(target)), Self::Dict(ts) => ts .iter() @@ -1273,8 +1273,8 @@ impl TyParam { Self::ProjCall { obj, args, .. } => { obj.contains_type(target) || args.iter().any(|t| t.contains_type(target)) } - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_type(target)), - Self::UnsizedArray(elem) => elem.contains_type(target), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_type(target)), + Self::UnsizedList(elem) => elem.contains_type(target), Self::Set(ts) => ts.iter().any(|t| t.contains_type(target)), Self::Dict(ts) => ts .iter() @@ -1303,8 +1303,8 @@ impl TyParam { Self::ProjCall { obj, args, .. } => { obj.contains_tp(target) || args.iter().any(|t| t.contains_tp(target)) } - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tp(target)), - Self::UnsizedArray(elem) => elem.contains_tp(target), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tp(target)), + Self::UnsizedList(elem) => elem.contains_tp(target), Self::Set(ts) => ts.iter().any(|t| t.contains_tp(target)), Self::Dict(ts) => ts .iter() @@ -1333,8 +1333,8 @@ impl TyParam { Self::UnaryOp { val, .. } => val.contains_tp(self), Self::App { args, .. } => args.iter().any(|t| t.contains_tp(self)), Self::Lambda(lambda) => lambda.body.iter().any(|t| t.contains_tp(self)), - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tp(self)), - Self::UnsizedArray(elem) => elem.contains_tp(self), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.contains_tp(self)), + Self::UnsizedList(elem) => elem.contains_tp(self), Self::Set(ts) => ts.iter().any(|t| t.contains_tp(self)), Self::Record(rec) | Self::DataClass { fields: rec, .. } => { rec.iter().any(|(_, t)| t.contains_tp(self)) @@ -1372,8 +1372,8 @@ impl TyParam { Self::ProjCall { obj, args, .. } => { obj.has_unbound_var() || args.iter().any(|t| t.has_unbound_var()) } - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.has_unbound_var()), - Self::UnsizedArray(elem) => elem.has_unbound_var(), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.has_unbound_var()), + Self::UnsizedList(elem) => elem.has_unbound_var(), Self::Set(ts) => ts.iter().any(|t| t.has_unbound_var()), Self::Dict(kv) => kv .iter() @@ -1403,8 +1403,8 @@ impl TyParam { Self::ProjCall { obj, args, .. } => { obj.has_undoable_linked_var() || args.iter().any(|t| t.has_undoable_linked_var()) } - Self::Array(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.has_undoable_linked_var()), - Self::UnsizedArray(elem) => elem.has_undoable_linked_var(), + Self::List(ts) | Self::Tuple(ts) => ts.iter().any(|t| t.has_undoable_linked_var()), + Self::UnsizedList(elem) => elem.has_undoable_linked_var(), Self::Set(ts) => ts.iter().any(|t| t.has_undoable_linked_var()), Self::Dict(kv) => kv .iter() @@ -1432,10 +1432,10 @@ impl TyParam { Self::ProjCall { obj, args, .. } => obj .union_size() .max(args.iter().map(|t| t.union_size()).max().unwrap_or(1)), - Self::Array(ts) | Self::Tuple(ts) => { + Self::List(ts) | Self::Tuple(ts) => { ts.iter().map(|t| t.union_size()).max().unwrap_or(1) } - Self::UnsizedArray(elem) => elem.union_size(), + Self::UnsizedList(elem) => elem.union_size(), Self::Set(ts) => ts.iter().map(|t| t.union_size()).max().unwrap_or(1), Self::Dict(kv) => kv .iter() @@ -1517,10 +1517,10 @@ impl TyParam { let new_val = val.substitute(var, to); TyParam::unary(op, new_val) } - TyParam::UnsizedArray(elem) => TyParam::unsized_array(elem.substitute(var, to)), - TyParam::Array(tps) => { + TyParam::UnsizedList(elem) => TyParam::unsized_list(elem.substitute(var, to)), + TyParam::List(tps) => { let new_tps = tps.into_iter().map(|t| t.substitute(var, to)).collect(); - TyParam::Array(new_tps) + TyParam::List(new_tps) } TyParam::Tuple(tps) => { let new_tps = tps.into_iter().map(|t| t.substitute(var, to)).collect(); @@ -1610,10 +1610,10 @@ impl TyParam { let new_val = val.replace(target, to); TyParam::unary(op, new_val) } - TyParam::UnsizedArray(elem) => TyParam::unsized_array(elem.replace(target, to)), - TyParam::Array(tps) => { + TyParam::UnsizedList(elem) => TyParam::unsized_list(elem.replace(target, to)), + TyParam::List(tps) => { let new_tps = tps.into_iter().map(|t| t.replace(target, to)).collect(); - TyParam::Array(new_tps) + TyParam::List(new_tps) } TyParam::Tuple(tps) => { let new_tps = tps.into_iter().map(|t| t.replace(target, to)).collect(); @@ -1844,12 +1844,12 @@ impl TyParam { arg.dereference(); } } - Self::Array(ts) | Self::Tuple(ts) => { + Self::List(ts) | Self::Tuple(ts) => { for t in ts { t.dereference(); } } - Self::UnsizedArray(elem) => elem.dereference(), + Self::UnsizedList(elem) => elem.dereference(), Self::Set(ts) => { let ts_ = std::mem::take(ts); *ts = ts_ @@ -1922,7 +1922,7 @@ impl TyParam { } set } - Self::Array(tps) | Self::Tuple(tps) => { + Self::List(tps) | Self::Tuple(tps) => { tps.iter().fold(set! {}, |acc, t| acc.concat(t.variables())) } Self::Set(tps) => tps.iter().fold(set! {}, |acc, t| acc.concat(t.variables())), @@ -1932,7 +1932,7 @@ impl TyParam { Self::Dict(tps) => tps.iter().fold(set! {}, |acc, (k, v)| { acc.concat(k.variables().concat(v.variables())) }), - Self::UnsizedArray(elem) => elem.variables(), + Self::UnsizedList(elem) => elem.variables(), Self::BinOp { lhs, rhs, .. } => lhs.variables().concat(rhs.variables()), Self::UnaryOp { val, .. } => val.variables(), Self::Lambda(lambda) => lambda diff --git a/crates/erg_compiler/ty/value.rs b/crates/erg_compiler/ty/value.rs index ae793fa25..0558bf1ee 100644 --- a/crates/erg_compiler/ty/value.rs +++ b/crates/erg_compiler/ty/value.rs @@ -25,7 +25,7 @@ use crate::context::Context; use self::value_set::inner_class; use super::codeobj::{tuple_into_bytes, CodeObj}; -use super::constructors::{array_t, dict_t, refinement, set_t, tuple_t, unsized_array_t}; +use super::constructors::{dict_t, list_t, refinement, set_t, tuple_t, unsized_list_t}; use super::typaram::{OpKind, TyParam}; use super::{ConstSubr, Field, HasType, Predicate, Type}; use super::{CONTAINER_OMIT_THRESHOLD, STR_OMIT_THRESHOLD}; @@ -502,8 +502,8 @@ pub enum ValueObj { Float(f64), Str(Str), Bool(bool), - Array(ArcArray), - UnsizedArray(Box), + List(ArcArray), + UnsizedList(Box), Set(Set), Dict(Dict), Tuple(ArcArray), @@ -562,8 +562,8 @@ impl fmt::Debug for ValueObj { write!(f, "False") } } - Self::Array(arr) => write!(f, "[{}]", fmt_iter(arr.iter())), - Self::UnsizedArray(elem) => write!(f, "[{elem}; _]"), + Self::List(lis) => write!(f, "[{}]", fmt_iter(lis.iter())), + Self::UnsizedList(elem) => write!(f, "[{elem}; _]"), Self::Dict(dict) => { write!(f, "{{")?; for (i, (k, v)) in dict.iter().enumerate() { @@ -624,9 +624,9 @@ impl LimitedDisplay for ValueObj { write!(f, "\"{}\"", s.escape()) } } - Self::Array(arr) => { + Self::List(lis) => { write!(f, "[")?; - for (i, item) in arr.iter().enumerate() { + for (i, item) in lis.iter().enumerate() { if i != 0 { write!(f, ", ")?; } @@ -751,8 +751,8 @@ impl Hash for ValueObj { Self::Float(f) => f.to_bits().hash(state), Self::Str(s) => s.hash(state), Self::Bool(b) => b.hash(state), - Self::Array(arr) => arr.hash(state), - Self::UnsizedArray(elem) => { + Self::List(lis) => lis.hash(state), + Self::UnsizedList(elem) => { "UnsizedArray".hash(state); elem.hash(state) } @@ -855,7 +855,7 @@ impl From for ValueObj { impl> From> for ValueObj { fn from(item: Vec) -> Self { - ValueObj::Array(ArcArray::from( + ValueObj::List(ArcArray::from( &item.into_iter().map(Into::into).collect::>()[..], )) } @@ -863,7 +863,7 @@ impl> From> for ValueObj { impl> From<[V; N]> for ValueObj { fn from(item: [V; N]) -> Self { - ValueObj::Array(ArcArray::from(&item.map(Into::into)[..])) + ValueObj::List(ArcArray::from(&item.map(Into::into)[..])) } } @@ -1031,8 +1031,8 @@ impl ValueObj { pub const fn is_container(&self) -> bool { matches!( self, - Self::Array(_) - | Self::UnsizedArray(_) + Self::List(_) + | Self::UnsizedList(_) | Self::Set(_) | Self::Dict(_) | Self::Tuple(_) @@ -1124,7 +1124,7 @@ impl ValueObj { Self::Str(s) => str_into_bytes(s, false), Self::Bool(true) => vec![DataTypePrefix::True as u8], Self::Bool(false) => vec![DataTypePrefix::False as u8], - Self::Array(elems) | Self::Tuple(elems) => tuple_into_bytes(&elems, python_ver), + Self::List(elems) | Self::Tuple(elems) => tuple_into_bytes(&elems, python_ver), Self::None => { vec![DataTypePrefix::None as u8] } @@ -1169,15 +1169,15 @@ impl ValueObj { Self::Float(_) => Type::Float, Self::Str(_) => Type::Str, Self::Bool(_) => Type::Bool, - Self::Array(arr) => array_t( + Self::List(lis) => list_t( // REVIEW: Never? - arr.iter() + lis.iter() .next() .map(|elem| elem.class()) .unwrap_or(Type::Never), - TyParam::value(arr.len()), + TyParam::value(lis.len()), ), - Self::UnsizedArray(elem) => unsized_array_t(elem.class()), + Self::UnsizedList(elem) => unsized_list_t(elem.class()), Self::Dict(dict) => { let tp = dict .iter() @@ -1295,9 +1295,9 @@ impl ValueObj { (Self::Nat(l), Self::Float(r)) => Some(Self::Float(l as f64 - r)), (Self::Float(l), Self::Int(r)) => Some(Self::Float(l - r as f64)), (Self::Str(l), Self::Str(r)) => Some(Self::Str(Str::from(format!("{l}{r}")))), - (Self::Array(l), Self::Array(r)) => { - let arr = Arc::from([l, r].concat()); - Some(Self::Array(arr)) + (Self::List(l), Self::List(r)) => { + let lis = Arc::from([l, r].concat()); + Some(Self::List(lis)) } (Self::Dict(l), Self::Dict(r)) => Some(Self::Dict(l.concat(r))), (inf @ (Self::Inf | Self::NegInf), _) | (_, inf @ (Self::Inf | Self::NegInf)) => { diff --git a/crates/erg_linter/lint.rs b/crates/erg_linter/lint.rs index 21086a3f7..29d9bf2af 100644 --- a/crates/erg_linter/lint.rs +++ b/crates/erg_linter/lint.rs @@ -8,7 +8,7 @@ use erg_common::traits::{BlockKind, ExitStatus, Locational, New, Runnable, Strea use erg_compiler::artifact::{Buildable, ErrorArtifact}; use erg_compiler::build_package::PackageBuilder; use erg_compiler::error::{CompileError, CompileErrors, CompileWarnings}; -use erg_compiler::hir::{Accessor, Array, Def, Dict, Expr, Set, Signature, Tuple}; +use erg_compiler::hir::{Accessor, Def, Dict, Expr, List, Set, Signature, Tuple}; use erg_compiler::module::SharedCompilerResource; use erg_parser::ParserRunner; @@ -189,21 +189,21 @@ impl Linter { } } } - Expr::Array(array) => match array { - Array::Normal(arr) => { - for elem in arr.elems.pos_args.iter() { + Expr::List(list) => match list { + List::Normal(lis) => { + for elem in lis.elems.pos_args.iter() { lint_fn(self, &elem.expr); } } - Array::WithLength(arr) => { - lint_fn(self, &arr.elem); - if let Some(len) = &arr.len { + List::WithLength(lis) => { + lint_fn(self, &lis.elem); + if let Some(len) = &lis.len { lint_fn(self, len); } } - Array::Comprehension(arr) => { - lint_fn(self, &arr.elem); - lint_fn(self, &arr.guard); + List::Comprehension(lis) => { + lint_fn(self, &lis.elem); + lint_fn(self, &lis.guard); } }, Expr::Tuple(tuple) => match tuple { diff --git a/crates/erg_parser/ast.rs b/crates/erg_parser/ast.rs index c9dccbee8..e99785f7b 100644 --- a/crates/erg_parser/ast.rs +++ b/crates/erg_parser/ast.rs @@ -202,7 +202,7 @@ pub fn fmt_lines<'a, T: NestedDisplay + 'a>( } /// リテラルに実際の値が格納された構造体(定数畳み込み用) -/// ArrayやDictはまた別に +/// ListやDictはまた別に #[pyclass(get_all, set_all)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Literal { @@ -865,13 +865,13 @@ impl Accessor { #[pyclass(get_all, set_all)] #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NormalArray { +pub struct NormalList { pub l_sqbr: Token, pub r_sqbr: Token, pub elems: Args, } -impl NestedDisplay for NormalArray { +impl NestedDisplay for NormalList { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { writeln!(f, "[")?; self.elems.fmt_nest(f, level + 1)?; @@ -879,11 +879,11 @@ impl NestedDisplay for NormalArray { } } -impl_display_from_nested!(NormalArray); -impl_locational!(NormalArray, l_sqbr, elems, r_sqbr); +impl_display_from_nested!(NormalList); +impl_locational!(NormalList, l_sqbr, elems, r_sqbr); #[pymethods] -impl NormalArray { +impl NormalList { #[pyo3(name = "get")] fn _get(&self, index: usize) -> Option { self.get(index).cloned() @@ -899,7 +899,7 @@ impl NormalArray { } } -impl NormalArray { +impl NormalList { pub fn get(&self, index: usize) -> Option<&Expr> { self.elems.pos_args.get(index).map(|a| &a.expr) } @@ -911,24 +911,24 @@ impl NormalArray { #[pyclass] #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayWithLength { +pub struct ListWithLength { pub l_sqbr: Token, pub r_sqbr: Token, pub elem: Box, pub len: Box, } -impl NestedDisplay for ArrayWithLength { +impl NestedDisplay for ListWithLength { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!(f, "[{}; {}]", self.elem, self.len) } } -impl_display_from_nested!(ArrayWithLength); -impl_locational!(ArrayWithLength, l_sqbr, elem, r_sqbr); +impl_display_from_nested!(ListWithLength); +impl_locational!(ListWithLength, l_sqbr, elem, r_sqbr); #[pymethods] -impl ArrayWithLength { +impl ListWithLength { #[staticmethod] pub fn new(l_sqbr: Token, r_sqbr: Token, elem: PosArg, len: Expr) -> Self { Self { @@ -942,7 +942,7 @@ impl ArrayWithLength { #[pyclass] #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayComprehension { +pub struct ListComprehension { pub l_sqbr: Token, pub r_sqbr: Token, pub layout: Option>, @@ -950,7 +950,7 @@ pub struct ArrayComprehension { pub guard: Option>, } -impl NestedDisplay for ArrayComprehension { +impl NestedDisplay for ListComprehension { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { let mut generators = String::new(); for (name, gen) in self.generators.iter() { @@ -966,11 +966,11 @@ impl NestedDisplay for ArrayComprehension { } } -impl_display_from_nested!(ArrayComprehension); -impl_locational!(ArrayComprehension, l_sqbr, r_sqbr); +impl_display_from_nested!(ListComprehension); +impl_locational!(ListComprehension, l_sqbr, r_sqbr); #[pymethods] -impl ArrayComprehension { +impl ListComprehension { #[staticmethod] #[pyo3(signature = (l_sqbr, r_sqbr, layout, generators, guard=None))] pub fn new( @@ -991,22 +991,22 @@ impl ArrayComprehension { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Array { - Normal(NormalArray), - WithLength(ArrayWithLength), - Comprehension(ArrayComprehension), +pub enum List { + Normal(NormalList), + WithLength(ListWithLength), + Comprehension(ListComprehension), } -impl_nested_display_for_enum!(Array; Normal, WithLength, Comprehension); -impl_display_for_enum!(Array; Normal, WithLength, Comprehension); -impl_locational_for_enum!(Array; Normal, WithLength, Comprehension); -impl_into_py_for_enum!(Array; Normal, WithLength, Comprehension); -impl_from_py_for_enum!(Array; Normal(NormalArray), WithLength(ArrayWithLength), Comprehension(ArrayComprehension)); +impl_nested_display_for_enum!(List; Normal, WithLength, Comprehension); +impl_display_for_enum!(List; Normal, WithLength, Comprehension); +impl_locational_for_enum!(List; Normal, WithLength, Comprehension); +impl_into_py_for_enum!(List; Normal, WithLength, Comprehension); +impl_from_py_for_enum!(List; Normal(NormalList), WithLength(ListWithLength), Comprehension(ListComprehension)); -impl Array { +impl List { pub fn get(&self, index: usize) -> Option<&Expr> { match self { - Self::Normal(array) => array.get(index), + Self::Normal(list) => list.get(index), _ => None, } } @@ -2167,36 +2167,36 @@ impl ConstAccessor { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum ConstArray { - Normal(ConstNormalArray), - WithLength(ConstArrayWithLength), +pub enum ConstList { + Normal(ConstNormalList), + WithLength(ConstListWithLength), } -impl_nested_display_for_enum!(ConstArray; Normal, WithLength); -impl_display_from_nested!(ConstArray); -impl_locational_for_enum!(ConstArray; Normal, WithLength); -impl_into_py_for_enum!(ConstArray; Normal, WithLength); -impl_from_py_for_enum!(ConstArray; Normal(ConstNormalArray), WithLength(ConstArrayWithLength)); +impl_nested_display_for_enum!(ConstList; Normal, WithLength); +impl_display_from_nested!(ConstList); +impl_locational_for_enum!(ConstList; Normal, WithLength); +impl_into_py_for_enum!(ConstList; Normal, WithLength); +impl_from_py_for_enum!(ConstList; Normal(ConstNormalList), WithLength(ConstListWithLength)); -impl ConstArray { - pub fn downgrade(self) -> Array { +impl ConstList { + pub fn downgrade(self) -> List { match self { - Self::Normal(normal) => Array::Normal(normal.downgrade()), - Self::WithLength(with_length) => Array::WithLength(with_length.downgrade()), + Self::Normal(normal) => List::Normal(normal.downgrade()), + Self::WithLength(with_length) => List::WithLength(with_length.downgrade()), } } } #[pyclass] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct ConstNormalArray { +pub struct ConstNormalList { pub l_sqbr: Token, pub r_sqbr: Token, pub elems: ConstArgs, pub guard: Option>, } -impl NestedDisplay for ConstNormalArray { +impl NestedDisplay for ConstNormalList { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { if let Some(guard) = &self.guard { write!(f, "[{} | {}]", self.elems, guard) @@ -2206,11 +2206,11 @@ impl NestedDisplay for ConstNormalArray { } } -impl_display_from_nested!(ConstNormalArray); -impl_locational!(ConstNormalArray, l_sqbr, elems, r_sqbr); +impl_display_from_nested!(ConstNormalList); +impl_locational!(ConstNormalList, l_sqbr, elems, r_sqbr); #[pymethods] -impl ConstNormalArray { +impl ConstNormalList { #[staticmethod] pub fn new(l_sqbr: Token, r_sqbr: Token, elems: ConstArgs, guard: Option) -> Self { Self { @@ -2222,32 +2222,32 @@ impl ConstNormalArray { } } -impl ConstNormalArray { - pub fn downgrade(self) -> NormalArray { - NormalArray::new(self.l_sqbr, self.r_sqbr, self.elems.downgrade()) +impl ConstNormalList { + pub fn downgrade(self) -> NormalList { + NormalList::new(self.l_sqbr, self.r_sqbr, self.elems.downgrade()) } } #[pyclass] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct ConstArrayWithLength { +pub struct ConstListWithLength { pub l_sqbr: Token, pub r_sqbr: Token, pub elem: Box, pub length: Box, } -impl NestedDisplay for ConstArrayWithLength { +impl NestedDisplay for ConstListWithLength { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!(f, "[{}; {}]", self.elem, self.length) } } -impl_display_from_nested!(ConstArrayWithLength); -impl_locational!(ConstArrayWithLength, l_sqbr, elem, r_sqbr); +impl_display_from_nested!(ConstListWithLength); +impl_locational!(ConstListWithLength, l_sqbr, elem, r_sqbr); #[pymethods] -impl ConstArrayWithLength { +impl ConstListWithLength { #[staticmethod] pub fn new(l_sqbr: Token, r_sqbr: Token, elem: ConstExpr, length: ConstExpr) -> Self { Self { @@ -2259,9 +2259,9 @@ impl ConstArrayWithLength { } } -impl ConstArrayWithLength { - pub fn downgrade(self) -> ArrayWithLength { - ArrayWithLength::new( +impl ConstListWithLength { + pub fn downgrade(self) -> ListWithLength { + ListWithLength::new( self.l_sqbr, self.r_sqbr, PosArg::new(self.elem.downgrade()), @@ -2830,7 +2830,7 @@ pub enum ConstExpr { Lit(Literal), Accessor(ConstAccessor), App(ConstApp), - Array(ConstArray), + List(ConstList), Set(ConstSet), Dict(ConstDict), Tuple(ConstTuple), @@ -2842,11 +2842,11 @@ pub enum ConstExpr { TypeAsc(ConstTypeAsc), } -impl_nested_display_for_chunk_enum!(ConstExpr; Lit, Accessor, App, Array, Set, Dict, Tuple, Record, BinOp, UnaryOp, Def, Lambda, Set, TypeAsc); +impl_nested_display_for_chunk_enum!(ConstExpr; Lit, Accessor, App, List, Set, Dict, Tuple, Record, BinOp, UnaryOp, Def, Lambda, Set, TypeAsc); impl_display_from_nested!(ConstExpr); -impl_locational_for_enum!(ConstExpr; Lit, Accessor, App, Array, Set, Dict, Tuple, Record, BinOp, UnaryOp, Def, Lambda, Set, TypeAsc); -impl_into_py_for_enum!(ConstExpr; Lit, Accessor, App, Array, Set, Dict, Tuple, Record, Def, Lambda, BinOp, UnaryOp, TypeAsc); -impl_from_py_for_enum!(ConstExpr; Lit(Literal), Accessor(ConstAccessor), App(ConstApp), Array(ConstArray), Set(ConstSet), Dict(ConstDict), Tuple(ConstTuple), Record(ConstRecord), Def(ConstDef), Lambda(ConstLambda), BinOp(ConstBinOp), UnaryOp(ConstUnaryOp), TypeAsc(ConstTypeAsc)); +impl_locational_for_enum!(ConstExpr; Lit, Accessor, App, List, Set, Dict, Tuple, Record, BinOp, UnaryOp, Def, Lambda, Set, TypeAsc); +impl_into_py_for_enum!(ConstExpr; Lit, Accessor, App, List, Set, Dict, Tuple, Record, Def, Lambda, BinOp, UnaryOp, TypeAsc); +impl_from_py_for_enum!(ConstExpr; Lit(Literal), Accessor(ConstAccessor), App(ConstApp), List(ConstList), Set(ConstSet), Dict(ConstDict), Tuple(ConstTuple), Record(ConstRecord), Def(ConstDef), Lambda(ConstLambda), BinOp(ConstBinOp), UnaryOp(ConstUnaryOp), TypeAsc(ConstTypeAsc)); impl TryFrom<&ParamPattern> for ConstExpr { type Error = (); @@ -2856,7 +2856,7 @@ impl TryFrom<&ParamPattern> for ConstExpr { Ok(ConstExpr::Accessor(ConstAccessor::local(name.0.clone()))) } ParamPattern::Lit(lit) => Ok(ConstExpr::Lit(lit.clone())), - ParamPattern::Array(array) => ConstExpr::try_from(array), + ParamPattern::List(list) => ConstExpr::try_from(list), ParamPattern::Tuple(tuple) => ConstExpr::try_from(tuple), _ => Err(()), } @@ -2878,7 +2878,7 @@ impl ConstExpr { Self::Lit(lit) => Expr::Literal(lit), Self::Accessor(acc) => Expr::Accessor(acc.downgrade()), Self::App(app) => Expr::Call(app.downgrade()), - Self::Array(arr) => Expr::Array(arr.downgrade()), + Self::List(lis) => Expr::List(lis.downgrade()), Self::Set(set) => Expr::Set(set.downgrade()), Self::Dict(dict) => Expr::Dict(dict.downgrade()), Self::Tuple(tuple) => Expr::Tuple(tuple.downgrade()), @@ -3338,19 +3338,19 @@ impl SubrTypeSpec { #[pyclass] #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ArrayTypeSpec { +pub struct ListTypeSpec { pub sqbrs: Option<(Token, Token)>, pub ty: Box, pub len: ConstExpr, } -impl fmt::Display for ArrayTypeSpec { +impl fmt::Display for ListTypeSpec { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "[{}; {}]", self.ty, self.len) } } -impl Locational for ArrayTypeSpec { +impl Locational for ListTypeSpec { fn loc(&self) -> Location { if let Some((lsqbr, rsqbr)) = &self.sqbrs { Location::concat(lsqbr, rsqbr) @@ -3360,7 +3360,7 @@ impl Locational for ArrayTypeSpec { } } -impl ArrayTypeSpec { +impl ListTypeSpec { pub fn new(ty: TypeSpec, len: ConstExpr, sqbrs: Option<(Token, Token)>) -> Self { Self { ty: Box::new(ty), @@ -3529,7 +3529,7 @@ impl RefinementTypeSpec { } } -/// * Array: `[Int; 3]`, `[Int, Ratio, Complex]`, etc. +/// * List: `[Int; 3]`, `[Int, Ratio, Complex]`, etc. /// * Dict: `[Str: Str]`, etc. /// * And (Intersection type): Add and Sub and Mul (== Num), etc. /// * Not (Diff type): Pos == Nat not {0}, etc. @@ -3545,7 +3545,7 @@ pub enum TypeSpec { Infer(Token), PreDeclTy(PreDeclTypeSpec), /* Composite types */ - Array(ArrayTypeSpec), + List(ListTypeSpec), SetWithLen(SetWithLenTypeSpec), Tuple(TupleTypeSpec), Dict(DictTypeSpec), @@ -3584,7 +3584,7 @@ impl fmt::Display for TypeSpec { Self::And(lhs, rhs) => write!(f, "{lhs} and {rhs}"), Self::Not(ty) => write!(f, "not {ty}"), Self::Or(lhs, rhs) => write!(f, "{lhs} or {rhs}"), - Self::Array(arr) => write!(f, "{arr}"), + Self::List(lis) => write!(f, "{lis}"), Self::SetWithLen(set) => write!(f, "{set}"), Self::Tuple(tup) => write!(f, "{tup}"), Self::Dict(dict) => dict.fmt(f), @@ -3613,7 +3613,7 @@ impl Locational for TypeSpec { Location::concat(lhs.as_ref(), rhs.as_ref()) } Self::Not(ty) => ty.loc(), - Self::Array(arr) => arr.loc(), + Self::List(lis) => lis.loc(), Self::SetWithLen(set) => set.loc(), Self::Tuple(tup) => tup.loc(), Self::Dict(dict) => dict.loc(), @@ -4253,21 +4253,21 @@ impl Identifier { #[pyclass(get_all, set_all)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct VarArrayPattern { +pub struct VarListPattern { l_sqbr: Token, pub(crate) elems: Vars, r_sqbr: Token, } -impl fmt::Display for VarArrayPattern { +impl fmt::Display for VarListPattern { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "[{}]", self.elems) } } -impl_locational!(VarArrayPattern, l_sqbr, r_sqbr); +impl_locational!(VarListPattern, l_sqbr, r_sqbr); -impl Stream for VarArrayPattern { +impl Stream for VarListPattern { #[inline] fn payload(self) -> Vec { self.elems.payload() @@ -4282,7 +4282,7 @@ impl Stream for VarArrayPattern { } } -impl VarArrayPattern { +impl VarListPattern { pub const fn new(l_sqbr: Token, elems: Vars, r_sqbr: Token) -> Self { Self { l_sqbr, @@ -4439,7 +4439,7 @@ pub enum VarPattern { Discard(Token), Ident(Identifier), /// e.g. `[x, y, z]` of `[x, y, z] = [1, 2, 3]` - Array(VarArrayPattern), + List(VarListPattern), /// e.g. `(x, y, z)` of `(x, y, z) = (1, 2, 3)` Tuple(VarTuplePattern), // e.g. `{name; age}`, `{_; [car, cdr]}` @@ -4453,7 +4453,7 @@ impl NestedDisplay for VarPattern { match self { Self::Discard(_) => write!(f, "_"), Self::Ident(ident) => write!(f, "{ident}"), - Self::Array(a) => write!(f, "{a}"), + Self::List(l) => write!(f, "{l}"), Self::Tuple(t) => write!(f, "{t}"), Self::Record(r) => write!(f, "{r}"), Self::DataPack(d) => write!(f, "{d}"), @@ -4462,9 +4462,9 @@ impl NestedDisplay for VarPattern { } impl_display_from_nested!(VarPattern); -impl_locational_for_enum!(VarPattern; Discard, Ident, Array, Tuple, Record, DataPack); -impl_into_py_for_enum!(VarPattern; Discard, Ident, Array, Tuple, Record, DataPack); -impl_from_py_for_enum!(VarPattern; Discard(Token), Ident(Identifier), Array(VarArrayPattern), Tuple(VarTuplePattern), Record(VarRecordPattern), DataPack(VarDataPackPattern)); +impl_locational_for_enum!(VarPattern; Discard, Ident, List, Tuple, Record, DataPack); +impl_into_py_for_enum!(VarPattern; Discard, Ident, List, Tuple, Record, DataPack); +impl_from_py_for_enum!(VarPattern; Discard(Token), Ident(Identifier), List(VarListPattern), Tuple(VarTuplePattern), Record(VarRecordPattern), DataPack(VarDataPackPattern)); impl VarPattern { pub const fn inspect(&self) -> Option<&Str> { @@ -4643,31 +4643,31 @@ impl Vars { #[pyclass(get_all, set_all)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct ParamArrayPattern { +pub struct ParamListPattern { pub l_sqbr: Token, pub elems: Params, pub r_sqbr: Token, } -impl NestedDisplay for ParamArrayPattern { +impl NestedDisplay for ParamListPattern { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { write!(f, "[{}]", self.elems) } } -impl_display_from_nested!(ParamArrayPattern); -impl_locational!(ParamArrayPattern, l_sqbr, r_sqbr); +impl_display_from_nested!(ParamListPattern); +impl_locational!(ParamListPattern, l_sqbr, r_sqbr); -impl TryFrom<&ParamArrayPattern> for Expr { +impl TryFrom<&ParamListPattern> for Expr { type Error = (); - fn try_from(value: &ParamArrayPattern) -> Result { + fn try_from(value: &ParamListPattern) -> Result { let mut new = vec![]; for elem in value.elems.non_defaults.iter() { new.push(PosArg::new(Expr::try_from(&elem.pat)?)); } let elems = Args::pos_only(new, None); - Ok(Expr::Array(Array::Normal(NormalArray::new( + Ok(Expr::List(List::Normal(NormalList::new( value.l_sqbr.clone(), value.r_sqbr.clone(), elems, @@ -4675,16 +4675,16 @@ impl TryFrom<&ParamArrayPattern> for Expr { } } -impl TryFrom<&ParamArrayPattern> for ConstExpr { +impl TryFrom<&ParamListPattern> for ConstExpr { type Error = (); - fn try_from(value: &ParamArrayPattern) -> Result { + fn try_from(value: &ParamListPattern) -> Result { let mut new = vec![]; for elem in value.elems.non_defaults.iter() { new.push(ConstPosArg::new(ConstExpr::try_from(&elem.pat)?)); } let elems = ConstArgs::pos_only(new, None); - Ok(ConstExpr::Array(ConstArray::Normal(ConstNormalArray::new( + Ok(ConstExpr::List(ConstList::Normal(ConstNormalList::new( value.l_sqbr.clone(), value.r_sqbr.clone(), elems, @@ -4694,7 +4694,7 @@ impl TryFrom<&ParamArrayPattern> for ConstExpr { } #[pymethods] -impl ParamArrayPattern { +impl ParamListPattern { #[staticmethod] pub const fn new(l_sqbr: Token, elems: Params, r_sqbr: Token) -> Self { Self { @@ -4851,7 +4851,7 @@ pub enum ParamPattern { VarName(VarName), // TODO: ConstAttr(), Lit(Literal), - Array(ParamArrayPattern), + List(ParamListPattern), Tuple(ParamTuplePattern), Record(ParamRecordPattern), // DataPack(ParamDataPackPattern), @@ -4859,7 +4859,7 @@ pub enum ParamPattern { RefMut(VarName), } -impl_into_py_for_enum!(ParamPattern; Discard, VarName, Lit, Array, Tuple, Record, Ref, RefMut); +impl_into_py_for_enum!(ParamPattern; Discard, VarName, Lit, List, Tuple, Record, Ref, RefMut); impl NestedDisplay for ParamPattern { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { @@ -4867,7 +4867,7 @@ impl NestedDisplay for ParamPattern { Self::Discard(tok) => write!(f, "{tok}"), Self::VarName(var_name) => write!(f, "{var_name}"), Self::Lit(lit) => write!(f, "{lit}"), - Self::Array(array) => write!(f, "{array}"), + Self::List(list) => write!(f, "{list}"), Self::Tuple(tuple) => write!(f, "{tuple}"), Self::Record(record) => write!(f, "{record}"), Self::Ref(var_name) => write!(f, "ref {var_name}"), @@ -4885,7 +4885,7 @@ impl TryFrom<&ParamPattern> for Expr { Ok(Expr::Accessor(Accessor::local(name.0.clone()))) } ParamPattern::Lit(lit) => Ok(Expr::Literal(lit.clone())), - ParamPattern::Array(array) => Expr::try_from(array), + ParamPattern::List(list) => Expr::try_from(list), ParamPattern::Tuple(tuple) => Expr::try_from(tuple), _ => Err(()), } @@ -4893,7 +4893,7 @@ impl TryFrom<&ParamPattern> for Expr { } impl_display_from_nested!(ParamPattern); -impl_locational_for_enum!(ParamPattern; Discard, VarName, Lit, Array, Tuple, Record, Ref, RefMut); +impl_locational_for_enum!(ParamPattern; Discard, VarName, Lit, List, Tuple, Record, Ref, RefMut); impl ParamPattern { pub const fn inspect(&self) -> Option<&Str> { @@ -5890,7 +5890,7 @@ impl Compound { pub enum Expr { Literal(Literal), Accessor(Accessor), - Array(Array), + List(List), Tuple(Tuple), Dict(Dict), Set(Set), @@ -5912,12 +5912,12 @@ pub enum Expr { Dummy(Dummy), } -impl_nested_display_for_chunk_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); -impl_from_trait_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); +impl_nested_display_for_chunk_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); +impl_from_trait_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); impl_display_from_nested!(Expr); -impl_locational_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); -impl_into_py_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); -impl_from_py_for_enum!(Expr; Literal, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); +impl_locational_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); +impl_into_py_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); +impl_from_py_for_enum!(Expr; Literal, Accessor, List, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAscription, Def, Methods, ClassDef, PatchDef, ReDef, Compound, InlineModule, Dummy); impl Expr { pub fn is_match_call(&self) -> bool { @@ -5939,7 +5939,7 @@ impl Expr { match self { Self::Literal(_) => "literal", Self::Accessor(_) => "accessor", - Self::Array(_) => "array", + Self::List(_) => "list", Self::Tuple(_) => "tuple", Self::Dict(_) => "dict", Self::Set(_) => "set", @@ -6075,9 +6075,9 @@ impl Expr { } sum } - Self::Array(Array::Normal(arr)) => { + Self::List(List::Normal(lis)) => { let mut sum = 0; - for elem in arr.elems.pos_args.iter() { + for elem in lis.elems.pos_args.iter() { sum += elem.expr.complexity(); } sum diff --git a/crates/erg_parser/convert.rs b/crates/erg_parser/convert.rs index 78c9d3a13..f8302715d 100644 --- a/crates/erg_parser/convert.rs +++ b/crates/erg_parser/convert.rs @@ -27,11 +27,11 @@ impl Parser { debug_exit_info!(self); Ok(Signature::Subr(subr)) } - Expr::Array(array) => { - let array_pat = self - .convert_array_to_array_pat(array) + Expr::List(list) => { + let list_pat = self + .convert_list_to_list_pat(list) .map_err(|_| self.stack_dec(fn_name!()))?; - let var = VarSignature::new(VarPattern::Array(array_pat), None); + let var = VarSignature::new(VarPattern::List(list_pat), None); debug_exit_info!(self); Ok(Signature::Var(var)) } @@ -96,12 +96,12 @@ impl Parser { } } - fn convert_array_to_array_pat(&mut self, array: Array) -> ParseResult { + fn convert_list_to_list_pat(&mut self, list: List) -> ParseResult { debug_call_info!(self); - match array { - Array::Normal(arr) => { + match list { + List::Normal(lis) => { let mut vars = Vars::empty(); - for elem in arr.elems.pos_args { + for elem in lis.elems.pos_args { let pat = self .convert_rhs_to_sig(elem.expr) .map_err(|_| self.stack_dec(fn_name!()))?; @@ -117,7 +117,7 @@ impl Parser { } } } - if let Some(var) = arr.elems.var_args { + if let Some(var) = lis.elems.var_args { let pat = self .convert_rhs_to_sig(var.expr) .map_err(|_| self.stack_dec(fn_name!()))?; @@ -133,21 +133,21 @@ impl Parser { } } } - let pat = VarArrayPattern::new(arr.l_sqbr, vars, arr.r_sqbr); + let pat = VarListPattern::new(lis.l_sqbr, vars, lis.r_sqbr); debug_exit_info!(self); Ok(pat) } - Array::Comprehension(arr) => { - let err = ParseError::simple_syntax_error(line!() as usize, arr.loc()); + List::Comprehension(lis) => { + let err = ParseError::simple_syntax_error(line!() as usize, lis.loc()); self.errs.push(err); debug_exit_info!(self); Err(()) } - Array::WithLength(arr) => { + List::WithLength(lis) => { let err = ParseError::feature_error( line!() as usize, - arr.loc(), - "array-with-length pattern", + lis.loc(), + "list-with-length pattern", ); self.errs.push(err); debug_exit_info!(self); @@ -480,11 +480,11 @@ impl Parser { debug_exit_info!(self); Ok(param) } - Expr::Array(array) => { - let array_pat = self - .convert_array_to_param_array_pat(array) + Expr::List(list) => { + let list_pat = self + .convert_list_to_param_list_pat(list) .map_err(|_| self.stack_dec(fn_name!()))?; - let pat = ParamPattern::Array(array_pat); + let pat = ParamPattern::List(list_pat); let param = NonDefaultParamSignature::new(pat, None); debug_exit_info!(self); Ok(param) @@ -570,17 +570,17 @@ impl Parser { Ok(param) } - fn convert_array_to_param_array_pat(&mut self, array: Array) -> ParseResult { + fn convert_list_to_param_list_pat(&mut self, list: List) -> ParseResult { debug_call_info!(self); - match array { - Array::Normal(arr) => { + match list { + List::Normal(lis) => { let mut params = vec![]; - for arg in arr.elems.into_iters().0 { + for arg in lis.elems.into_iters().0 { params.push(self.convert_pos_arg_to_non_default_param(arg, false)?); } let params = Params::new(params, None, vec![], None, None); debug_exit_info!(self); - Ok(ParamArrayPattern::new(arr.l_sqbr, params, arr.r_sqbr)) + Ok(ParamListPattern::new(lis.l_sqbr, params, lis.r_sqbr)) } other => { let err = ParseError::feature_error(line!() as usize, other.loc(), "?"); @@ -717,11 +717,11 @@ impl Parser { debug_exit_info!(self); Ok(LambdaSignature::new(params, None, TypeBoundSpecs::empty())) } - Expr::Array(array) => { - let arr = self - .convert_array_to_param_array_pat(array) + Expr::List(list) => { + let lis = self + .convert_list_to_param_list_pat(list) .map_err(|_| self.stack_dec(fn_name!()))?; - let param = NonDefaultParamSignature::new(ParamPattern::Array(arr), None); + let param = NonDefaultParamSignature::new(ParamPattern::List(lis), None); let params = Params::single(param); debug_exit_info!(self); Ok(LambdaSignature::new(params, None, TypeBoundSpecs::empty())) diff --git a/crates/erg_parser/desugar.rs b/crates/erg_parser/desugar.rs index 2b8b9ac55..38afed383 100644 --- a/crates/erg_parser/desugar.rs +++ b/crates/erg_parser/desugar.rs @@ -4,7 +4,6 @@ //! e.g. Literal parameters, Multi assignment //! 型チェックなどによる検証は行わない -use erg_common::consts::PYTHON_MODE; use erg_common::error::Location; use erg_common::fresh::FreshNameGenerator; use erg_common::traits::{Locational, Stream}; @@ -12,16 +11,15 @@ use erg_common::{debug_power_assert, Str}; use erg_common::{enum_unwrap, get_hash, log, set}; use crate::ast::{ - Accessor, Args, Array, ArrayComprehension, ArrayTypeSpec, ArrayWithLength, BinOp, Block, Call, - ClassAttr, ClassAttrs, ClassDef, Compound, ConstExpr, DataPack, Def, DefBody, DefId, - DefaultParamSignature, Dict, Dummy, Expr, GuardClause, Identifier, InlineModule, KeyValue, - KwArg, Lambda, LambdaSignature, Literal, Methods, MixedRecord, Module, - NonDefaultParamSignature, NormalArray, NormalDict, NormalRecord, NormalSet, NormalTuple, - ParamPattern, ParamRecordAttr, ParamTuplePattern, Params, PatchDef, PosArg, ReDef, Record, - RecordAttrOrIdent, RecordAttrs, RecordTypeSpec, Set as astSet, SetComprehension, SetWithLength, - Signature, SubrSignature, Tuple, TupleTypeSpec, TypeAppArgs, TypeAppArgsKind, TypeBoundSpecs, - TypeSpec, TypeSpecWithOp, UnaryOp, VarName, VarPattern, VarRecordAttr, VarSignature, - VisModifierSpec, AST, + Accessor, Args, BinOp, Block, Call, ClassAttr, ClassAttrs, ClassDef, Compound, ConstExpr, + DataPack, Def, DefBody, DefId, DefaultParamSignature, Dict, Dummy, Expr, GuardClause, + Identifier, InlineModule, KeyValue, KwArg, Lambda, LambdaSignature, List, ListComprehension, + ListTypeSpec, ListWithLength, Literal, Methods, MixedRecord, Module, NonDefaultParamSignature, + NormalDict, NormalList, NormalRecord, NormalSet, NormalTuple, ParamPattern, ParamRecordAttr, + ParamTuplePattern, Params, PatchDef, PosArg, ReDef, Record, RecordAttrOrIdent, RecordAttrs, + RecordTypeSpec, Set as astSet, SetComprehension, SetWithLength, Signature, SubrSignature, + Tuple, TupleTypeSpec, TypeAppArgs, TypeAppArgsKind, TypeBoundSpecs, TypeSpec, TypeSpecWithOp, + UnaryOp, VarName, VarPattern, VarRecordAttr, VarSignature, VisModifierSpec, AST, }; use crate::token::{Token, TokenKind, COLON, DOT}; @@ -57,7 +55,7 @@ pub fn symop_to_dname(op: &str) -> Option<&'static str> { #[derive(Debug, Clone, PartialEq, Eq)] enum BufIndex<'i> { - Array(usize), + List(usize), Tuple(usize), Record(&'i Identifier), } @@ -189,34 +187,34 @@ impl Desugarer { }; Expr::DataPack(DataPack::new(class, pack.connector, args)) } - 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 elems = elems .into_iter() .map(|elem| PosArg::new(desugar(elem.expr))) .collect(); let elems = Args::pos_only(elems, None); - let arr = NormalArray::new(arr.l_sqbr, arr.r_sqbr, elems); - Expr::Array(Array::Normal(arr)) + let lis = NormalList::new(lis.l_sqbr, lis.r_sqbr, elems); + Expr::List(List::Normal(lis)) } - Array::WithLength(arr) => { - let elem = PosArg::new(desugar(arr.elem.expr)); - let len = desugar(*arr.len); - let arr = ArrayWithLength::new(arr.l_sqbr, arr.r_sqbr, elem, len); - Expr::Array(Array::WithLength(arr)) + List::WithLength(lis) => { + let elem = PosArg::new(desugar(lis.elem.expr)); + let len = desugar(*lis.len); + let lis = ListWithLength::new(lis.l_sqbr, lis.r_sqbr, elem, len); + Expr::List(List::WithLength(lis)) } - Array::Comprehension(arr) => { - let layout = arr.layout.map(|ex| desugar(*ex)); - let generators = arr + List::Comprehension(lis) => { + let layout = lis.layout.map(|ex| desugar(*ex)); + let generators = lis .generators .into_iter() .map(|(ident, gen)| (ident, desugar(gen))) .collect(); - let guard = arr.guard.map(|ex| desugar(*ex)); - let arr = - ArrayComprehension::new(arr.l_sqbr, arr.r_sqbr, layout, generators, guard); - Expr::Array(Array::Comprehension(arr)) + let guard = lis.guard.map(|ex| desugar(*ex)); + let lis = + ListComprehension::new(lis.l_sqbr, lis.r_sqbr, layout, generators, guard); + Expr::List(List::Comprehension(lis)) } }, Expr::Tuple(tuple) => match tuple { @@ -718,16 +716,16 @@ impl Desugarer { self.desugar_rest_values(new, var, &buf_name, elems_len); } } - VarPattern::Array(arr) => { + VarPattern::List(lis) => { let (buf_name, buf_sig) = self.gen_buf_name_and_sig(v.loc(), v.t_spec); let body = self.desugar_pattern_in_body(body); let buf_def = Def::new(buf_sig, body); new.push(Expr::Def(buf_def)); - for (n, elem) in arr.elems.iter().enumerate() { - self.desugar_nested_var_pattern(new, elem, &buf_name, BufIndex::Array(n)); + for (n, elem) in lis.elems.iter().enumerate() { + self.desugar_nested_var_pattern(new, elem, &buf_name, BufIndex::List(n)); } - let elems_len = arr.elems.len(); - if let Some(var) = arr.elems.starred.as_ref() { + let elems_len = lis.elems.len(); + if let Some(var) = lis.elems.starred.as_ref() { self.desugar_rest_values(new, var, &buf_name, elems_len); } } @@ -886,7 +884,7 @@ impl Desugarer { ); let acc = match buf_index { BufIndex::Tuple(n) => obj.tuple_attr(Literal::nat(n, sig.ln_begin().unwrap_or(1))), - BufIndex::Array(n) => { + BufIndex::List(n) => { let r_brace = Token::new( TokenKind::RBrace, "]", @@ -921,17 +919,12 @@ impl Desugarer { ); } } - VarPattern::Array(arr) => { + VarPattern::List(lis) => { let (buf_name, buf_sig) = self.gen_buf_name_and_sig(sig.loc(), None); let buf_def = Def::new(buf_sig, body); new_module.push(Expr::Def(buf_def)); - for (n, elem) in arr.elems.iter().enumerate() { - self.desugar_nested_var_pattern( - new_module, - elem, - &buf_name, - BufIndex::Array(n), - ); + for (n, elem) in lis.elems.iter().enumerate() { + self.desugar_nested_var_pattern(new_module, elem, &buf_name, BufIndex::List(n)); } } VarPattern::Record(rec) => { @@ -1054,7 +1047,7 @@ impl Desugarer { NormalRecord::new(record.l_brace, record.r_brace, attrs) } - fn dummy_array_expr(len: Literal) -> Expr { + fn dummy_list_expr(len: Literal) -> Expr { let l_sqbr = Token { content: "[".into(), kind: TokenKind::LSqBr, @@ -1066,13 +1059,13 @@ impl Desugarer { ..len.token }; let elem = Expr::local("Obj", l_sqbr.lineno, l_sqbr.col_begin, l_sqbr.col_end); - let array = Array::WithLength(ArrayWithLength::new( + let list = List::WithLength(ListWithLength::new( l_sqbr, r_sqbr, PosArg::new(elem), Expr::Literal(len), )); - Expr::Array(array) + Expr::List(list) } fn dummy_set_expr(lit: Literal) -> Expr { @@ -1271,11 +1264,11 @@ impl Desugarer { param.pat = buf_param; guards } - ParamPattern::Array(arr) => { + ParamPattern::List(lis) => { fn const_check(expr: &Expr) -> bool { match &expr { Expr::Accessor(Accessor::Ident(ident)) => ident.is_const(), - Expr::Array(Array::Normal(arr)) => arr + Expr::List(List::Normal(lis)) => lis .elems .pos_args() .iter() @@ -1283,21 +1276,21 @@ impl Desugarer { _ => true, } } - let expr = Expr::try_from(&*arr).and_then(|expr| { + let expr = Expr::try_from(&*lis).and_then(|expr| { if const_check(&expr) { Ok(expr) } else { Err(()) } }); - let (buf_name, buf_param) = self.gen_buf_nd_param(arr.loc()); - guards.push(Self::len_guard(buf_name.clone(), arr.elems.len(), arr)); - for (n, elem) in arr.elems.non_defaults.iter_mut().enumerate() { - let gs = self.desugar_nested_param_pattern(elem, &buf_name, BufIndex::Array(n)); + let (buf_name, buf_param) = self.gen_buf_nd_param(lis.loc()); + guards.push(Self::len_guard(buf_name.clone(), lis.elems.len(), lis)); + for (n, elem) in lis.elems.non_defaults.iter_mut().enumerate() { + let gs = self.desugar_nested_param_pattern(elem, &buf_name, BufIndex::List(n)); guards.extend(gs); } if param.t_spec.is_none() { - let len = arr.elems.non_defaults.len(); + let len = lis.elems.non_defaults.len(); let len = Literal::new(Token::new_fake( TokenKind::NatLit, len.to_string(), @@ -1306,10 +1299,10 @@ impl Desugarer { 0, )); let infer = Token::new_fake(TokenKind::Try, "?", line, 0, 0); - let t_spec = ArrayTypeSpec::new( + let t_spec = ListTypeSpec::new( TypeSpec::Infer(infer), ConstExpr::Lit(len.clone()), - Some((arr.l_sqbr.clone(), arr.r_sqbr.clone())), + Some((lis.l_sqbr.clone(), lis.r_sqbr.clone())), ); // [1, 2] -> ... // => _: {[1, 2]} -> ... @@ -1320,11 +1313,11 @@ impl Desugarer { Args::single(PosArg::new(expr)), ))) } else { - Self::dummy_array_expr(len) + Self::dummy_list_expr(len) }; param.t_spec = Some(TypeSpecWithOp::new( Token::dummy(TokenKind::Colon, ":"), - TypeSpec::Array(t_spec), + TypeSpec::List(t_spec), t_spec_as_expr, )); } @@ -1419,7 +1412,7 @@ impl Desugarer { ); let acc = match buf_index { BufIndex::Tuple(n) => obj.tuple_attr(Literal::nat(n, sig.ln_begin().unwrap_or(1))), - BufIndex::Array(n) => { + BufIndex::List(n) => { let r_brace = Token::new( TokenKind::RBrace, "]", @@ -1490,8 +1483,8 @@ impl Desugarer { sig.pat = buf_sig; guards } - ParamPattern::Array(arr) => { - let (buf_name, buf_sig) = self.gen_buf_nd_param(arr.loc()); + ParamPattern::List(lis) => { + let (buf_name, buf_sig) = self.gen_buf_nd_param(lis.loc()); let def = Def::new( Signature::Var(VarSignature::new( VarPattern::Ident(Identifier::private(Str::from(&buf_name))), @@ -1500,13 +1493,13 @@ impl Desugarer { body, ); guards.push(GuardClause::Bind(def)); - guards.push(Self::len_guard(buf_name.clone(), arr.elems.len(), arr)); - for (n, elem) in arr.elems.non_defaults.iter_mut().enumerate() { - let gs = self.desugar_nested_param_pattern(elem, &buf_name, BufIndex::Array(n)); + guards.push(Self::len_guard(buf_name.clone(), lis.elems.len(), lis)); + for (n, elem) in lis.elems.non_defaults.iter_mut().enumerate() { + let gs = self.desugar_nested_param_pattern(elem, &buf_name, BufIndex::List(n)); guards.extend(gs); } if sig.t_spec.is_none() { - let len = arr.elems.non_defaults.len(); + let len = lis.elems.non_defaults.len(); let len = Literal::new(Token::new_fake( TokenKind::NatLit, len.to_string(), @@ -1515,15 +1508,15 @@ impl Desugarer { 0, )); let infer = Token::new_fake(TokenKind::Try, "?", line, 0, 0); - let t_spec = ArrayTypeSpec::new( + let t_spec = ListTypeSpec::new( TypeSpec::Infer(infer), ConstExpr::Lit(len.clone()), - Some((arr.l_sqbr.clone(), arr.r_sqbr.clone())), + Some((lis.l_sqbr.clone(), lis.r_sqbr.clone())), ); - let t_spec_as_expr = Self::dummy_array_expr(len); + let t_spec_as_expr = Self::dummy_list_expr(len); sig.t_spec = Some(TypeSpecWithOp::new( COLON, - TypeSpec::Array(t_spec), + TypeSpec::List(t_spec), t_spec_as_expr, )); } @@ -1754,8 +1747,8 @@ impl Desugarer { } /// ```erg - /// [y | x <- xs] ==> array(map(x -> y, xs)) - /// [(a, b) | x <- xs; y <- ys] ==> array(map(((x, y),) -> (a, b), itertools.product(xs, ys))) + /// [y | x <- xs] ==> list(map(x -> y, xs)) + /// [(a, b) | x <- xs; y <- ys] ==> list(map(((x, y),) -> (a, b), itertools.product(xs, ys))) /// {k: v | x <- xs} ==> dict(map(x -> (k, v), xs)) /// {y | x <- xs} ==> set(map(x -> y, xs)) /// {x <- xs | x <= 10} ==> set(filter(x -> x <= 10, xs)) @@ -1763,15 +1756,16 @@ impl Desugarer { /// ``` fn rec_desugar_comprehension(expr: Expr) -> Expr { match expr { - Expr::Array(Array::Comprehension(mut comp)) => { + Expr::List(List::Comprehension(mut comp)) => { debug_power_assert!(comp.generators.len(), >, 0); if comp.generators.len() != 1 { - return Expr::Array(Array::Comprehension(comp)); + return Expr::List(List::Comprehension(comp)); } let (ident, iter) = comp.generators.remove(0); let iterator = Self::desugar_layout_and_guard(ident, iter, comp.layout, comp.guard); - let array = if PYTHON_MODE { "list" } else { "array" }; - Identifier::auto(array.into()).call1(iterator.into()).into() + Identifier::auto("list".into()) + .call1(iterator.into()) + .into() } Expr::Dict(Dict::Comprehension(mut comp)) => { debug_power_assert!(comp.generators.len(), >, 0); diff --git a/crates/erg_parser/error.rs b/crates/erg_parser/error.rs index fa4d630d8..ae3e4f038 100644 --- a/crates/erg_parser/error.rs +++ b/crates/erg_parser/error.rs @@ -518,7 +518,7 @@ impl LexError { let method = StyledStr::new("メソッド", Some(HINT), Some(ATTR)); let lit = StyledStr::new("NatLit", Some(HINT), Some(ATTR)); let newline = StyledStr::new("改行", Some(HINT), Some(ATTR)); - let arr = StyledStr::new("配列", Some(HINT), Some(ATTR)); + let arr = StyledStr::new("リスト", Some(HINT), Some(ATTR)); format!("予期: {method}、{lit}、{newline}、{arr}") }, "simplified_chinese" => { @@ -539,7 +539,7 @@ impl LexError { let method = StyledStr::new("method", Some(HINT), Some(ATTR)); let lit = StyledStr::new("NatLit", Some(HINT), Some(ATTR)); let newline = StyledStr::new("newline", Some(HINT), Some(ATTR)); - let arr = StyledStr::new("array", Some(HINT), Some(ATTR)); + let arr = StyledStr::new("list", Some(HINT), Some(ATTR)); format!("expect: {method}, {lit}, {newline}, {arr}") }, ); diff --git a/crates/erg_parser/lib.rs b/crates/erg_parser/lib.rs index 9d30a8eff..b5d356381 100644 --- a/crates/erg_parser/lib.rs +++ b/crates/erg_parser/lib.rs @@ -40,7 +40,7 @@ pub fn erg_parser(py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(_parse, m)?)?; let expr = PyModule::new(py, "expr")?; expr.add_class::()?; - expr.add_class::()?; + expr.add_class::()?; expr.add_class::()?; expr.add_class::()?; expr.add_class::()?; @@ -71,7 +71,7 @@ pub fn erg_parser(py: Python<'_>, m: &PyModule) -> PyResult<()> { ast.add_class::()?; ast.add_class::()?; ast.add_class::()?; - ast.add_class::()?; + ast.add_class::()?; ast.add_class::()?; ast.add_class::()?; ast.add_class::()?; diff --git a/crates/erg_parser/parse.rs b/crates/erg_parser/parse.rs index a1345ac1b..e987a5b20 100644 --- a/crates/erg_parser/parse.rs +++ b/crates/erg_parser/parse.rs @@ -135,7 +135,7 @@ enum ArgKind { KwVar(PosArg), } -pub enum ArrayInner { +pub enum ListInner { Normal(Args), WithLength(PosArg, Expr), Comprehension { @@ -145,7 +145,7 @@ pub enum ArrayInner { }, } -impl ArrayInner { +impl ListInner { pub const fn comp( layout: Option, generators: Vec<(Identifier, Expr)>, @@ -857,7 +857,7 @@ impl Parser { Ok(acc) } - fn try_reduce_array_elems(&mut self) -> ParseResult { + fn try_reduce_list_elems(&mut self) -> ParseResult { debug_call_info!(self); if self.cur_is(EOF) { let tk = self.tokens.last().unwrap(); @@ -868,7 +868,7 @@ impl Parser { if self.cur_category_is(TC::REnclosure) { let args = Args::empty(); debug_exit_info!(self); - return Ok(ArrayInner::Normal(args)); + return Ok(ListInner::Normal(args)); } let first = self .try_reduce_elem() @@ -891,7 +891,7 @@ impl Parser { self.stack_dec(fn_name!()) })?; debug_exit_info!(self); - return Ok(ArrayInner::WithLength(elems.remove_pos(0), len)); + return Ok(ListInner::WithLength(elems.remove_pos(0), len)); } Some(PreStar) => { self.lpop(); @@ -900,7 +900,7 @@ impl Parser { .map_err(|_| self.stack_dec(fn_name!()))?; elems.set_var_args(PosArg::new(rest)); debug_exit_info!(self); - return Ok(ArrayInner::Normal(elems)); + return Ok(ListInner::Normal(elems)); } Some(Inclusion) => { self.lpop(); @@ -925,7 +925,7 @@ impl Parser { .try_reduce_expr(false, false, false, false) .map_err(|_| self.stack_dec(fn_name!()))?; debug_exit_info!(self); - return Ok(ArrayInner::comp(None, generators, Some(guard))); + return Ok(ListInner::comp(None, generators, Some(guard))); } Some(VBar) => { self.lpop(); @@ -956,7 +956,7 @@ impl Parser { None }; debug_exit_info!(self); - return Ok(ArrayInner::comp(Some(elem), generators, guard)); + return Ok(ListInner::comp(Some(elem), generators, guard)); } Some(RParen | RSqBr | RBrace | Dedent | Comma) => {} Some(_) => { @@ -1027,7 +1027,7 @@ impl Parser { } } debug_exit_info!(self); - Ok(ArrayInner::Normal(elems)) + Ok(ListInner::Normal(elems)) } fn try_reduce_elem(&mut self) -> ParseResult { @@ -2601,11 +2601,11 @@ impl Parser { Ok(expr) } Some(t) if t.is(LSqBr) => { - let array = self - .try_reduce_array() + let list = self + .try_reduce_list() .map_err(|_| self.stack_dec(fn_name!()))?; debug_exit_info!(self); - Ok(Expr::Array(array)) + Ok(Expr::List(list)) } Some(t) if t.is(LBrace) => { match self @@ -2874,15 +2874,15 @@ impl Parser { } #[inline] - fn try_reduce_array(&mut self) -> ParseResult { + fn try_reduce_list(&mut self) -> ParseResult { 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 { - match array { - Array::Normal(arr) => { + fn list_to_list_type_spec(list: List) -> Result { + match list { + List::Normal(lis) => { // TODO: add hint - let err = ParseError::simple_syntax_error(line!() as usize, arr.loc()); + let err = ParseError::simple_syntax_error(line!() as usize, lis.loc()); Err(err) } - Array::WithLength(arr) => { - let t_spec = Self::expr_to_type_spec(arr.elem.expr)?; - let len = Self::validate_const_expr(*arr.len)?; - Ok(ArrayTypeSpec::new( + List::WithLength(lis) => { + let t_spec = Self::expr_to_type_spec(lis.elem.expr)?; + let len = Self::validate_const_expr(*lis.len)?; + Ok(ListTypeSpec::new( t_spec, len, - Some((arr.l_sqbr, arr.r_sqbr)), + Some((lis.l_sqbr, lis.r_sqbr)), )) } - Array::Comprehension(arr) => { + List::Comprehension(lis) => { // TODO: add hint - let err = ParseError::simple_syntax_error(line!() as usize, arr.loc()); + let err = ParseError::simple_syntax_error(line!() as usize, lis.loc()); Err(err) } } @@ -508,9 +508,9 @@ impl Parser { let lambda = Self::lambda_to_subr_type_spec(lambda)?; Ok(TypeSpec::Subr(lambda)) } - Expr::Array(array) => { - let array = Self::array_to_array_type_spec(array)?; - Ok(TypeSpec::Array(array)) + Expr::List(list) => { + let list = Self::list_to_list_type_spec(list)?; + Ok(TypeSpec::List(list)) } Expr::Set(set) => { let set = Self::set_to_set_type_spec(set)?; diff --git a/doc/EN/API/funcs.md b/doc/EN/API/funcs.md index f58a58d5a..ea9028ede 100644 --- a/doc/EN/API/funcs.md +++ b/doc/EN/API/funcs.md @@ -52,7 +52,7 @@ Returns the class of `object`. However, since classes cannot be compared, use `object in Class` instead of `classof(object) == Class` if you want to judge instances. The structure type determined at compile time is obtained with `Typeof`. -## Iterator, Array generation system +## Iterator, List generation system ### repeat|T|(x: T) -> RepeatIterator T @@ -96,11 +96,11 @@ match jan: _ -> log "Other" ``` - ### Inherit Inherit classes. You can use the methods of the parent class ('Super') as is. The second parameter 'Layout' can specify a new layout. It must be 'Super.Base:> Layout'. + ```python @ Inheritable C = Class {i = Int} diff --git a/doc/EN/API/modules/repl.md b/doc/EN/API/modules/repl.md index a0782532d..d5c9baf71 100644 --- a/doc/EN/API/modules/repl.md +++ b/doc/EN/API/modules/repl.md @@ -20,5 +20,5 @@ Infers a function given its arguments and return value. ```python 1.guess((1,), 2) # -[1, 2].guess((3, 4), [1, 2, 3, 4]) # -``` \ No newline at end of file +[1, 2].guess((3, 4), [1, 2, 3, 4]) # +``` 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 ```

- Previous | Next + Previous | Next

diff --git a/doc/EN/syntax/10_array.md b/doc/EN/syntax/10_list.md similarity index 75% rename from doc/EN/syntax/10_array.md rename to doc/EN/syntax/10_list.md index aaa7544bc..735077886 100644 --- a/doc/EN/syntax/10_array.md +++ b/doc/EN/syntax/10_list.md @@ -1,6 +1,6 @@ -# Array +# List -Arrays are the most basic __collection (aggregate)__. +A list is the most basic __collection (aggregate)__. A collection is an object that can hold multiple objects inside it. ```python @@ -14,7 +14,7 @@ mut_a[0].inc!() assert mut_a == [2, 2, 3] ``` -As a rule, arrays cannot contain objects of different types. +As a rule, lists cannot contain objects of different types. ```python,compile_fail [1, "a"] # TypeError: 1st element is Int, but 2nd element is Str @@ -23,12 +23,12 @@ As a rule, arrays cannot contain objects of different types. However, you can bypass the restriction by explicitly specifying the type like this. ```python -[1: Int or Str, "a"] +[1, "a"]: [Int or Str; 2] ``` ## Slice -An array can also have multiple values taken out at once. This is called slicing. +A list can also have multiple values taken out at once. This is called slicing. ```python l = [1, 2, 3, 4] @@ -41,7 +41,7 @@ assert l[1..1] == [2] assert l[..].step(2) == [2, 4] ``` -The object obtained by slicing is an (immutable) copy to an array. +The object obtained by slicing is an (immutable) copy to a list. ```python print! Typeof l[1..2] # [Int; 4] diff --git a/doc/EN/syntax/11_dict.md b/doc/EN/syntax/11_dict.md index b353fc575..4c0ff0f01 100644 --- a/doc/EN/syntax/11_dict.md +++ b/doc/EN/syntax/11_dict.md @@ -7,7 +7,7 @@ ids = {"Alice": 145, "Bob": 214, "Charlie": 301} assert ids["Alice"] == 145 ``` -The key does not have to be a string if it is a `Hashable` object. +The key does not have to be a string if it is a `Hash` object. ```python # deprecated to use a range object as a key (confused with slice) @@ -73,5 +73,5 @@ x = "a" ```

- Previous | Next -

\ No newline at end of file + Previous | Next +

diff --git a/doc/EN/syntax/18_iterator.md b/doc/EN/syntax/18_iterator.md index b390168fc..6c7b05c17 100644 --- a/doc/EN/syntax/18_iterator.md +++ b/doc/EN/syntax/18_iterator.md @@ -32,22 +32,22 @@ The type `{Iterator}` of the `.Iterator` attribute is so-called set-kind (kind i ```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() # ``` -Both `ArrayIterator` and `RangeIterator` are classes that implement `Iterator` and exist only to give `Array` and `Range` iteration functions. +Both `ListIterator` and `RangeIterator` are classes that implement `Iterator` and exist only to give `List` and `Range` iteration functions. Such a design pattern is called companion class [1](#1). -And the `IteratorImpl` patch is the core of the iteration functionality. `Iterator` requires only one `.next` method, `IteratorImpl` provides dozens of methods indeed. `ArrayIterator` and `RangeIterator` can use the implementation method of `IteratorImpl` just by implementing the `.next` method. For this convenience, the standard library implements a number of iterators. +And the `IteratorImpl` patch is the core of the iteration functionality. `Iterator` requires only one `.next` method, `IteratorImpl` provides dozens of methods indeed. `ListIterator` and `RangeIterator` can use the implementation method of `IteratorImpl` just by implementing the `.next` method. For this convenience, the standard library implements a number of iterators. ```mermaid classDiagram - class Array~T~ { + class List~T~ { ... - iter() ArrayIterator~T~ + iter() ListIterator~T~ } class Range~T~ { ... @@ -57,10 +57,10 @@ classDiagram <> iter() Iterator~T~ } - Iterable~T~ <|.. Array~T~: Impl + Iterable~T~ <|.. List~T~: Impl Iterable~T~ <|.. Range~T~: Impl - class ArrayIterator~T~ { - array: Array~T~ + class ListIterator~T~ { + list: List~T~ next() T } class RangeIterator~T~ { @@ -71,10 +71,10 @@ classDiagram <> next() T } - Iterator~T~ <|.. ArrayIterator~T~: Impl + Iterator~T~ <|.. ListIterator~T~: Impl Iterator~T~ <|.. RangeIterator~T~: Impl - Array <-- ArrayIterator + List <-- ListIterator Range <-- RangeIterator ``` diff --git a/doc/EN/syntax/19_mutability.md b/doc/EN/syntax/19_mutability.md index 932e1cc16..597421764 100644 --- a/doc/EN/syntax/19_mutability.md +++ b/doc/EN/syntax/19_mutability.md @@ -31,7 +31,7 @@ print! id! _a # 0x000002A798DFE980 The `id!` procedure returns the address in memory where the object resides. -`b` is a `Nat` "dynamic" array. The content of the object changes, but the variables point to the same thing. +`b` is a `Nat` "dynamic" list. The content of the object changes, but the variables point to the same thing. ```python b = ![1, 2, 3] diff --git a/doc/EN/syntax/20_ownership.md b/doc/EN/syntax/20_ownership.md index 3c02c185d..57b240c33 100644 --- a/doc/EN/syntax/20_ownership.md +++ b/doc/EN/syntax/20_ownership.md @@ -36,11 +36,11 @@ A subroutine that needs to duplicate an object is said to be an "argument consum ```python capitalize s: Str!= - s. capitalize!() + s.capitalize!() s s1 = !"hello" -s2 = capitalize s1.clone() +s2 = capitalize s1.copy() log s2, s1 # !"HELLO hello" ``` diff --git a/doc/EN/syntax/25_closure.md b/doc/EN/syntax/25_closure.md index d0f5fb834..9365aec1c 100644 --- a/doc/EN/syntax/25_closure.md +++ b/doc/EN/syntax/25_closure.md @@ -41,7 +41,7 @@ Call `.clone` if you want the contents of the mutable object at the time the fun ```python i = !0 -immut_i = i.clone().freeze() +immut_i = i.copy().freeze() fx = immut_i + x assert f 1 == 1 i.add! 1 diff --git a/doc/EN/syntax/28_pattern_matching.md b/doc/EN/syntax/28_pattern_matching.md index 93a1b40ae..7ad39e4ac 100644 --- a/doc/EN/syntax/28_pattern_matching.md +++ b/doc/EN/syntax/28_pattern_matching.md @@ -23,7 +23,7 @@ fn: Int -> Int = x -> x + 1 # higher-order type a: [Int; 4] = [0, 1, 2, 3] # or -a: Array Int, 4 = [0, 1, 2, 3] +a: List Int, 4 = [0, 1, 2, 3] ``` ### Literal patterns @@ -66,8 +66,8 @@ name = match num: ```python,checker_ignore # these two are the same -Array(T, N: {N | N >= 3}) -Array(T, N | N >= 3) +List(T, N: {N | N >= 3}) +List(T, N | N >= 3) f M, N | M >= 0, N >= 1 = ... f(1, 0) # TypeError: N (2nd parameter) must be 1 or more @@ -106,7 +106,7 @@ m, n = 1, 2 f(x, y) = ... ``` -### array pattern +### list pattern ```python [i, j] = [1, 2] diff --git a/doc/EN/syntax/29_comprehension.md b/doc/EN/syntax/29_comprehension.md index 6fd4dfdf7..1d78f5801 100644 --- a/doc/EN/syntax/29_comprehension.md +++ b/doc/EN/syntax/29_comprehension.md @@ -1,6 +1,6 @@ # Comprehension -You can create an Array with `[(expr |)? (name <- iterable;)+ (| predicate)?]`, +You can create an List with `[(expr |)? (name <- iterable;)+ (| predicate)?]`, a set with `{(expr |)? (name <- iterable;)+ (| predicate)?}`, a Dict with `{(key: value |)? (name <- iterable;)+ (| predicate)?}`. diff --git a/doc/EN/syntax/33_pipeline.md b/doc/EN/syntax/33_pipeline.md index 63dd7ab0d..7805fdacf 100644 --- a/doc/EN/syntax/33_pipeline.md +++ b/doc/EN/syntax/33_pipeline.md @@ -17,14 +17,14 @@ log rand # 0.2597... 1+1*2 |>.times do log("a", end := "") # aaa -evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect Array +evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect List # When implemented without the pipeline operator, -_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(Array) +_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(List) # or __evens = 1..100 \ .iter() \ .filter i -> i % 2 == 0 \ - .collect Array + .collect List ```

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]}

Previous | Next -

\ 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.. U <: T (oblivion rule) ``` -Arrays like the one below are not valid types. It is an intentional design to emphasize that the elements of the array are homogenized. +Lists like the one below are not valid types. It is an intentional design to emphasize that the elements of the array are homogenized. ```erg [Int, Str] diff --git a/doc/EN/syntax/type/advanced/erasure.md b/doc/EN/syntax/type/advanced/erasure.md index ff485c46d..cf98d528f 100644 --- a/doc/EN/syntax/type/advanced/erasure.md +++ b/doc/EN/syntax/type/advanced/erasure.md @@ -2,7 +2,7 @@ Type erasure is the process of setting a type argument to `_` and deliberately discarding its information. Type erasure is a feature of many polymorphic languages, but in the context of Erg's syntax, it is more accurate to call it type argument erasure. -The most common example of a type that has been type-erased is `[T, _]`. Arrays are not always known their length at compile-time. For example, `sys.argv`, which refers to command line arguments, is of type `[Str, _]`. Since Erg's compiler has no way of knowing the length of command line arguments, information about their length must be given up. +The most common example of a type that has been type-erased is `[T, _]`. Lists are not always known their length at compile-time. For example, `sys.argv`, which refers to command line arguments, is of type `[Str, _]`. Since Erg's compiler has no way of knowing the length of command line arguments, information about their length must be given up. However, a type that has been type-erased becomes a supertype of a type that has not been (e.g. `[T; N] <: [T; _]`), so it can accept more objects. Objects of type `[T; N]` can of course use methods of type `[T; _]`, but the `N` information is erased after use. If the length does not change, then it is possible to use `[T; N]` in the signature. If the length remains the same, it must be indicated by a signature. @@ -18,14 +18,14 @@ For non-type type arguments (Int, Bool, etc.), the parameter with `_` will be un ```python i: _ # i: Object -[_; _] == [Object; _] == Array +[_; _] == [Object; _] == List ``` Type erasure is not the same as omitting a type specification. Once the type argument information has been erased, it will not be returned unless you assert it again. ```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)) ``` In Rust, this corresponds to the following code. @@ -38,6 +38,6 @@ Erg does not allow partial omission of types, but uses higher-order kind polymor ```python # collect is a higher-order Kind method that takes 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/EN/syntax/type/advanced/kind.md b/doc/EN/syntax/type/advanced/kind.md index 5c8526997..9776f75ce 100644 --- a/doc/EN/syntax/type/advanced/kind.md +++ b/doc/EN/syntax/type/advanced/kind.md @@ -2,7 +2,7 @@ Everything is typed in Erg. Types themselves are no exception. __kind__ represents the "type of type". For example, `Int` belongs to `Type`, just as `1` belongs to `Int`. `Type` is the simplest kind, the __atomic kind__. In type-theoretic notation, `Type` corresponds to `*`. -In the concept of kind, what is practically important is one or more kinds (multinomial kind). One-term kind, for example `Option`, belongs to it. A unary kind is represented as `Type -> Type` [1](#1). A __container__ such as `Array` or `Option` is specifically a polynomial kind that takes a type as an argument. +In the concept of kind, what is practically important is one or more kinds (multinomial kind). One-term kind, for example `Option`, belongs to it. A unary kind is represented as `Type -> Type` [1](#1). A __container__ such as `List` or `Option` is specifically a polynomial kind that takes a type as an argument. As the notation `Type -> Type` indicates, `Option` is actually a function that receives a type `T` and returns a type `Option T`. However, since this function is not a function in the usual sense, it is usually called the unary kind. Note that `->` itself, which is an anonymous function operator, can also be seen as a kind when it receives a type and returns a type. diff --git a/doc/EN/syntax/type/advanced/mut_struct.md b/doc/EN/syntax/type/advanced/mut_struct.md index b23de3c92..cf8ff9fc1 100644 --- a/doc/EN/syntax/type/advanced/mut_struct.md +++ b/doc/EN/syntax/type/advanced/mut_struct.md @@ -26,7 +26,7 @@ v: [Str; !1]. ``` For mutable structure types, Mutable type arguments are marked with `!`. In the above case, the type `[Str; !0]` can be changed to `[Str; !1]` and so on. That is, the length can be changed. -Incidentally, the `[T; !N]` type is the sugar-coated syntax of the `ArrayWithLength!(T, !N)` type. +Incidentally, the `[T; !N]` type is the sugar-coated syntax of the `ListWithLength!(T, !N)` type. Mutable structure types can of course be user-defined. Note, however, that there are some differences from invariant structure types in terms of the construction method. diff --git a/doc/EN/syntax/type/advanced/quantified_dependent.md b/doc/EN/syntax/type/advanced/quantified_dependent.md index 623f206f2..f322efcfa 100644 --- a/doc/EN/syntax/type/advanced/quantified_dependent.md +++ b/doc/EN/syntax/type/advanced/quantified_dependent.md @@ -4,7 +4,7 @@ Erg has quantified and dependent types. Then naturally, it is possible to create ```python NonNullStr = |N: Nat| StrWithLen N | N ! = 0 # same as {S | N: Nat; S: StrWithLen N; N ! = 0} -NonEmptyArray = |N: Nat| [_; N | N > 0] # same as {A | N: Nat; A: Array(_, N); N > 0} +NonEmptyList = |N: Nat| [_; N | N > 0] # same as {A | N: Nat; A: List(_, N); N > 0} ``` The standard form of quantified dependent types are `K(A, ... | Pred)`. ``K`` is a type constructor, `A, B` are type arguments, and `Pred` is a conditional expression. diff --git a/doc/EN/syntax/type/advanced/variance.md b/doc/EN/syntax/type/advanced/variance.md index 0519743c0..01828e4bd 100644 --- a/doc/EN/syntax/type/advanced/variance.md +++ b/doc/EN/syntax/type/advanced/variance.md @@ -5,19 +5,19 @@ Erg can subtype polymorphic types, but there are some caveats. First, consider the inclusion relation of ordinary polymorphic types. In general, there is a container `K` and a type `A, B` to which it assigns, and when `A < B`, `K A < K B`. For example, `Option Int < Option Object`. Therefore, methods defined in `Option Object` can also be used in `Option Int`. -Consider the typical polymorphic type `Array!(T)`. -Note that this time it's not `Array!(T, N)` because we don't care about the number of elements. -Now, the `Array!(T)` type has methods called `.push!` and `.pop!`, which mean adding and removing elements, respectively. Here is the type: +Consider the typical polymorphic type `List!(T)`. +Note that this time it's not `List!(T, N)` because we don't care about the number of elements. +Now, the `List!(T)` type has methods called `.push!` and `.pop!`, which mean adding and removing elements, respectively. Here is the type: -Array.push!: Self(T).(T) => NoneType -Array.pop!: Self(T).() => T +List.push!: Self(T).(T) => NoneType +List.pop!: Self(T).() => T As can be intuitively understood, -* `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 is. In terms of the type system, this is diff --git a/doc/EN/unify_terms.md b/doc/EN/unify_terms.md index abac7e762..4a8fa275e 100644 --- a/doc/EN/unify_terms.md +++ b/doc/EN/unify_terms.md @@ -46,11 +46,6 @@ Use attributes. By the way, a record is a function that can define an object wit Giving arguments to a subroutine object and getting a result. Use Call. This is because Application has a usage of "application software". -## Array, List - -Use Arrays. Erg arrays are (generally) contiguous in memory. -List refers to a so-called linked list, or a list as a Python data type. - ## lambda functions, lambda expressions, anonymous functions Unify with anonymous functions. In English, Lambda can be used to shorten the number of characters, but the official name is Anonymous function. diff --git a/doc/JA/API/funcs.md b/doc/JA/API/funcs.md index 0dc00b3a7..918c4e3cd 100644 --- a/doc/JA/API/funcs.md +++ b/doc/JA/API/funcs.md @@ -56,7 +56,7 @@ codeをコードとして評価し返す。 ただしクラスは比較できないため、インスタンス判定がしたい場合は`classof(object) == Class`ではなく`object in Class`を使う。 コンパイル時に決定される構造型は`Typeof`で得られる。 -## Iterator, Array生成系 +## Iterator, List生成系 ### repeat|T|(x: T) -> RepeatIterator T diff --git a/doc/JA/API/modules/repl.md b/doc/JA/API/modules/repl.md index 5199ad863..59ecc89f4 100644 --- a/doc/JA/API/modules/repl.md +++ b/doc/JA/API/modules/repl.md @@ -22,5 +22,5 @@ provides REPL(Read-Eval-Print-Loop)-related APIs. ```python 1.guess((1,), 2) # -[1, 2].guess((3, 4), [1, 2, 3, 4]) # +[1, 2].guess((3, 4), [1, 2, 3, 4]) # ``` diff --git a/doc/JA/API/types/classes/Array!(T,N).md b/doc/JA/API/types/classes/List!(T,N).md similarity index 67% rename from doc/JA/API/types/classes/Array!(T,N).md rename to doc/JA/API/types/classes/List!(T,N).md index 3161a18e3..f1a9973a9 100644 --- a/doc/JA/API/types/classes/Array!(T,N).md +++ b/doc/JA/API/types/classes/List!(T,N).md @@ -1,6 +1,6 @@ -# Array! T: Type, N: Nat +# List! T: Type, N: Nat -[![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/API/types/classes/Array!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) +[![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/API/types/classes/List!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) コンパイル時に長さのわかる可変長配列。`[T; N]!`という糖衣構文もある。 @@ -13,17 +13,14 @@ * sample!(ref! self) -> T * sample! ref! self, M: Nat -> [T; M] - 中の要素をランダムに選んでコピーを返す。 * shuffle!(ref! self) - 中身をシャッフルする。 * assert_len ref! self(_ ~> N, ...), N: Nat -> () or Panic - 長さを検証する。 長さが不正な場合は`panic!`する。 diff --git a/doc/JA/API/types/classes/Array(T,N).md b/doc/JA/API/types/classes/List(T,N).md similarity index 70% rename from doc/JA/API/types/classes/Array(T,N).md rename to doc/JA/API/types/classes/List(T,N).md index 657f31ac9..4e21b98fc 100644 --- a/doc/JA/API/types/classes/Array(T,N).md +++ b/doc/JA/API/types/classes/List(T,N).md @@ -1,6 +1,6 @@ -# Array T: Type, N: Nat +# List T: Type, N: Nat -[![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/API/types/classes/Array(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) +[![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/API/types/classes/List(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) `[T; N]`は糖衣構文。 @@ -25,7 +25,7 @@ assert ["a", "b", "c", "d", "e"].values_at([0, 1, 3]) == ["a", "b", "d"] assert all(False for _ in []) ``` -## methods of ArrayWithLen T, N | T <: Eq +## methods of ListWithLen T, N | T <: Eq * freq self -> [{T: Nat}] オブジェクトの出現頻度を返す。 diff --git a/doc/JA/API/types/traits/Hashable.md b/doc/JA/API/types/traits/Hash.md similarity index 77% rename from doc/JA/API/types/traits/Hashable.md rename to doc/JA/API/types/traits/Hash.md index d1930f350..a74c8aa89 100644 --- a/doc/JA/API/types/traits/Hashable.md +++ b/doc/JA/API/types/traits/Hash.md @@ -1,4 +1,4 @@ -# Hashable +# Hash ## required methods diff --git a/doc/JA/compiler/attribute_resolution.md b/doc/JA/compiler/attribute_resolution.md index 73596b20e..5a000d1ed 100644 --- a/doc/JA/compiler/attribute_resolution.md +++ b/doc/JA/compiler/attribute_resolution.md @@ -32,10 +32,10 @@ c: ?2 Ergでは関数の型検査はモジュール内で閉じているので、モジュール外で`co_consts`を属性に持つ型が定義されていても、そのインスタンスを`consts`関数に渡すとエラーになります(それを可能にするためには、後述する`Structural`を使う必要があります)。この制約によって`consts`関数の推論が可能になります。 型推論器は、クラス属性が定義されるとき、その"属性"と"定義クラス、属性の型"のペアを記録しておきます。 -`co_consts`の場合は`{co_consts: {Code, Array(Obj, _)}}`というペアです。 +`co_consts`の場合は`{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}], ...} ``` key-valueペアのvalueが配列になっていることに注意してください。この配列が長さ1であるとき、または(部分型関係による)最小の要素が存在するときのみ、keyは一意に特定できたということになります(そうでなければ型エラーが発生します)。 @@ -43,11 +43,11 @@ key-valueペアのvalueが配列になっていることに注意してくださ keyが特定できたら、その定義型を`?2`の型に逆伝搬させます。 ```erg -?2(<: Code).co_consts: Array(Obj, _) +?2(<: Code).co_consts: List(Obj, _) ``` -最終的に、`consts`の型は`Code -> Array(Obj, _)`となります。 +最終的に、`consts`の型は`Code -> List(Obj, _)`となります。 ```erg -consts(c: Code): Array(Obj, _) = c.co_consts +consts(c: Code): List(Obj, _) = c.co_consts ``` diff --git a/doc/JA/compiler/hir.md b/doc/JA/compiler/hir.md index aa7046f12..4b46b9d06 100644 --- a/doc/JA/compiler/hir.md +++ b/doc/JA/compiler/hir.md @@ -27,7 +27,7 @@ AST(Module[ body: Block[ UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), }, ], }, @@ -84,7 +84,7 @@ HIR(Module[ body: Block[ expr: UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), t: [0..10, 0]!, }, ], diff --git a/doc/JA/compiler/inference.md b/doc/JA/compiler/inference.md index e13447718..d8eb10c41 100644 --- a/doc/JA/compiler/inference.md +++ b/doc/JA/compiler/inference.md @@ -52,19 +52,19 @@ Ergの型推論は、大枠としてHindley-Milner型推論アルゴリズムを line 1. Def{sig: v, block: ![]} get block type: get UnaryOp type: - get Array type: `['T; 0]` + get List type: `['T; 0]` instantiate: `[?T; 0]` (substitute, eval are omitted) update: `Γ: {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!({1})` - 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!({1}) => NoneType` + get obj type: `List!(?T, 0)` + search: `Γ List!(?T, 0).push!({1})` + 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!({1}) => NoneType` update: `Γ: {v: [Nat; 1]!}` expr returns `NoneType`: OK diff --git a/doc/JA/compiler/parsing.md b/doc/JA/compiler/parsing.md index f9cc89893..49fb4d90c 100644 --- a/doc/JA/compiler/parsing.md +++ b/doc/JA/compiler/parsing.md @@ -23,8 +23,8 @@ Ergにおいて左辺値とは`=`の左側といった単純なものではな 右辺値の中に左辺値が存在することさえある。 ```python -# iは左辺値、Array(Int)と[1, 2, 3]は右辺値 -i: Array(Int) = [1, 2, 3] +# iは左辺値、List(Int)と[1, 2, 3]は右辺値 +i: List(Int) = [1, 2, 3] # `[1, 2, 3].iter().map i -> i + 1`は右辺値だが、->の左側のiは左辺値 a = [1, 2, 3].iter().map i -> i + 1 # {x = 1; y = 2}は右辺値だが、x, yは左辺値 diff --git a/doc/JA/compiler/pattern_matching.md b/doc/JA/compiler/pattern_matching.md index 01da7cfa3..f0dee6787 100644 --- a/doc/JA/compiler/pattern_matching.md +++ b/doc/JA/compiler/pattern_matching.md @@ -42,7 +42,7 @@ TypeがIntersection型(e.g. `Int and Str`)の場合は、`isinstance(i, Int) and Typeが篩型(e.g. `{I: Int | I >= 0}`)の場合は、中の述語式を評価することで行われる。`{1}`は`{I: Int | I == 1}`の構文糖であったから、`i == 1`が行われる。 -最後に、Typeが多相型・依存型(e.g. `Array(Int, 3)`)の場合は定義に従って検査するべき属性・メソッドが決定される。 +最後に、Typeが多相型・依存型(e.g. `List(Int, 3)`)の場合は定義に従って検査するべき属性・メソッドが決定される。 `F(X)`型の検査を考える。定義が`F(A <-> E) = ...`(`E`中に現れる`Self`はオブジェクト自身に置換される)であるとき、`fits(X, E)`で検査される。 @@ -53,13 +53,13 @@ fits X, E = else := do X == E ``` -`Array`の定義は +`List`の定義は ```erg -Array T <-> Union Self.iter().map(Typeof), N <-> Self.__len__() = ... +List T <-> Union Self.iter().map(Typeof), N <-> Self.__len__() = ... ``` -である。なので、`Array(Int, 3)`の検査としては`isinstance(i, Array) and subtypeof(Int, Union(i.iter().map(Typeof))) and i.__len__() == 3`が行われる。 +である。なので、`List(Int, 3)`の検査としては`isinstance(i, List) and subtypeof(Int, Union(i.iter().map(Typeof))) and i.__len__() == 3`が行われる。 ## リテラルパターン diff --git a/doc/JA/dev_guide/runtime.md b/doc/JA/dev_guide/runtime.md index c88958cfd..50bc99c8a 100644 --- a/doc/JA/dev_guide/runtime.md +++ b/doc/JA/dev_guide/runtime.md @@ -2,7 +2,7 @@ ## [_erg_array.py](https://github.com/erg-lang/erg/blob/d1dc1e60e7d4e3333f80ed23c5ead77b5fe47cb2/crates/erg_compiler/lib/std/_erg_array.py) -`list`のラッパーである`Array`クラスを定義します。 +`list`のラッパーである`List`クラスを定義します。 ## [_erg_bool.py](https://github.com/erg-lang/erg/blob/d1dc1e60e7d4e3333f80ed23c5ead77b5fe47cb2/crates/erg_compiler/lib/std/_erg_bool.py) diff --git a/doc/JA/faq_technical.md b/doc/JA/faq_technical.md index 3cdc505f6..44d1d1d5f 100644 --- a/doc/JA/faq_technical.md +++ b/doc/JA/faq_technical.md @@ -37,10 +37,10 @@ A: ErgのAPIはなるべくPythonのAPIの仕様に忠実に型付けられて ## Tupleにはなぜコンストラクタ(`__call__`)がないのですか? Ergのタプルは長さがコンパイル時に決まっている必要があります。そのため、タプルを構築する手段はほぼリテラルのみです。 -長さが実行まで不定の場合、代わりに不変配列(`Array`)を使うことになります。Ergの不変配列はPythonのタプルとほぼ同じです。 +長さが実行まで不定の場合、代わりに不変配列(`List`)を使うことになります。Ergの不変配列はPythonのタプルとほぼ同じです。 ```erg -arr = Array map(int, input!().split " ") +arr = List map(int, input!().split " ") ``` ## Pythonでは発生しなかった実行時エラーがErgでは発生しました。原因として何が考えられますか? diff --git a/doc/JA/syntax/01_literal.md b/doc/JA/syntax/01_literal.md index 5a14736a0..1aa3f00e0 100644 --- a/doc/JA/syntax/01_literal.md +++ b/doc/JA/syntax/01_literal.md @@ -76,7 +76,7 @@ assert 1e-10 == 0.0000000001 これらのリテラルは、それぞれ単独で解説されているドキュメントがあるので、詳しくはそちらを参照してください。 -### [配列リテラル(Array Literal)](./10_array.md) +### [リストリテラル(List Literal)](./10_list.md) ```python [], [1], [1, 2, 3], ["1", "2",], ... @@ -106,7 +106,7 @@ assert 1e-10 == 0.0000000001 {}, {1}, {1, 2, 3}, {"1", "2", "1"}, ... ``` -`Array`リテラルとの違いとして、`Set`では重複する要素が取り除かれます。 +`List`リテラルとの違いとして、`Set`では重複する要素が取り除かれます。 集合演算を行うときや、重複を許さないデータを扱うときに便利です。 ```python diff --git a/doc/JA/syntax/02_name.md b/doc/JA/syntax/02_name.md index b7d510e2e..b9e3ce4e0 100644 --- a/doc/JA/syntax/02_name.md +++ b/doc/JA/syntax/02_name.md @@ -28,12 +28,12 @@ n: Nat = 1 l1 = l2 = [1, 2, 3] # SyntaxError: multiple assignment not allowed ``` -このようなことをしたい場合、`.clone()`を使います。これはオブジェクトのコピーを作成します。 +このようなことをしたい場合は、単に以下のようにします。 ```python # OK l1 = [1, 2, 3] -l2 = l1.clone() +l2 = l1 ``` また、変数への再代入もできません。その代わりに使える機能、すなわち可変な状態を保持する機能については後述します。 diff --git a/doc/JA/syntax/04_function.md b/doc/JA/syntax/04_function.md index 5b1545115..c9a593f2d 100644 --- a/doc/JA/syntax/04_function.md +++ b/doc/JA/syntax/04_function.md @@ -130,7 +130,7 @@ f x := 1, y := x = ... # NG log "Hello", "World", "!" # Hello World ! ``` -このような関数を定義したいときは、仮引数に`*`を付けます。このようにすると、引数を可変長の配列として受け取ることができます。 +このような関数を定義したいときは、仮引数に`*`を付けます。このようにすると、引数を可変長のリストとして受け取ることができます。 ```python f *x: Int = diff --git a/doc/JA/syntax/09_builtin_procs.md b/doc/JA/syntax/09_builtin_procs.md index a7d55dab7..6e44e225a 100644 --- a/doc/JA/syntax/09_builtin_procs.md +++ b/doc/JA/syntax/09_builtin_procs.md @@ -11,5 +11,5 @@ ```

- 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() # +log [1, 2, 3].iter() # log (1..3).iter() # ``` -`ArrayIterator`と`RangeIterator`はどちらも`Iterator`を実装するクラスで、`Array`, `Range`にイテレーション機能を与えるためだけに存在します。 +`ListIterator`と`RangeIterator`はどちらも`Iterator`を実装するクラスで、`List`, `Range`にイテレーション機能を与えるためだけに存在します。 このようなデザインパターンをコンパニオンクラス[1](#1)と呼びます。 -そして`IteratorImpl`パッチがイテレーション機能のコアです。`Iterator`は`.next`メソッド1つだけを要求し、`IteratorImpl`は実に数十個のメソッドを提供します。`ArrayIterator`や`RangeIterator`は`.next`メソッドを実装するだけで`IteratorImpl`の実装メソッドを使うことができるわけです。この利便性から、標準ライブラリでは多数のイテレータが実装されています。 +そして`IteratorImpl`パッチがイテレーション機能のコアです。`Iterator`は`.next`メソッド1つだけを要求し、`IteratorImpl`は実に数十個のメソッドを提供します。`ListIterator`や`RangeIterator`は`.next`メソッドを実装するだけで`IteratorImpl`の実装メソッドを使うことができるわけです。この利便性から、標準ライブラリでは多数のイテレータが実装されています。 ```mermaid classDiagram - class Array~T~ { + class List~T~ { ... - iter() ArrayIterator~T~ + iter() ListIterator~T~ } class Range~T~ { ... @@ -59,10 +59,10 @@ classDiagram <> iter() Iterator~T~ } - Iterable~T~ <|.. Array~T~: Impl + Iterable~T~ <|.. List~T~: Impl Iterable~T~ <|.. Range~T~: Impl - class ArrayIterator~T~ { - array: Array~T~ + class ListIterator~T~ { + array: List~T~ next() T } class RangeIterator~T~ { @@ -73,10 +73,10 @@ classDiagram <> next() T } - Iterator~T~ <|.. ArrayIterator~T~: Impl + Iterator~T~ <|.. ListIterator~T~: Impl Iterator~T~ <|.. RangeIterator~T~: Impl - Array <-- ArrayIterator + List <-- ListIterator Range <-- RangeIterator ``` diff --git a/doc/JA/syntax/19_mutability.md b/doc/JA/syntax/19_mutability.md index e6038cad5..afa35c271 100644 --- a/doc/JA/syntax/19_mutability.md +++ b/doc/JA/syntax/19_mutability.md @@ -21,7 +21,7 @@ print! b # [1, 2, 3, 4, 5, 6] ``` `a, b`は、最終的な結果は同じように見えますが、その意味は大きく異なります。 -`a`は`Nat`の配列を示す変数ですが、1行目と2行目では指しているオブジェクトが異なります。`a`という名前が同じだけで、中身はさし変わっているのです。 +`a`は`Nat`のリストを示す変数ですが、1行目と2行目では指しているオブジェクトが異なります。`a`という名前が同じだけで、中身はさし変わっているのです。 ```python a = [1, 2, 3] @@ -32,7 +32,7 @@ print! id! _a # 0x000002A798DFE980 `id!`プロシージャはオブジェクトが存在するメモリ上のアドレスを返します。 -`b`は`Nat`の「動的」配列です。オブジェクトの中身は変わりますが、変数の指すものは同じです。 +`b`は`Nat`の「動的」リストです。オブジェクトの中身は変わりますが、変数の指すものは同じです。 ```python b = [1,2,3].into [Int; !3] diff --git a/doc/JA/syntax/20_ownership.md b/doc/JA/syntax/20_ownership.md index e28e4bf73..69f8e03f8 100644 --- a/doc/JA/syntax/20_ownership.md +++ b/doc/JA/syntax/20_ownership.md @@ -42,16 +42,16 @@ capitalize s: Str! = s s1 = !"hello" -s2 = capitalize s1.clone() +s2 = capitalize s1.copy() log s2, s1 # !"HELLO hello" ``` ## 凍結 不変オブジェクトは複数の場所から参照できることを利用して、可変オブジェクトを不変オブジェクトに変換します。 -これを凍結といいます。凍結は可変配列からイテレータを作るときなどで使われます。 -可変配列からは直接イテレータを作ることができないので、不変配列に変換します。 -配列を壊したくない場合は、[`.freeze_map`メソッド](./type/18_mut.md)等を使います。 +これを凍結といいます。凍結は可変リストからイテレータを作るときなどで使われます。 +可変リストからは直接イテレータを作ることができないので、不変リストに変換します。 +リストを壊したくない場合は、[`.freeze_map`メソッド](./type/18_mut.md)等を使います。 ```python # イテレータが出す値の合計を計算する @@ -97,7 +97,7 @@ steal_str ref(s: Str!) = ``` Ergの参照はRustより制約が強いです。参照は言語上第一級のオブジェクトですが、明示的に生成することはできず、`ref`/`ref!`によって実引数の渡し方として指定できるのみです。 -これは、参照を配列に詰めたり参照を属性とするクラスを作ったりはできないということを意味します。 +これは、参照をリストに詰めたり参照を属性とするクラスを作ったりはできないということを意味します。 とはいえ、このような制約はそもそも参照のない言語では当たり前の仕様であり、そこまで不便となることはありません。 diff --git a/doc/JA/syntax/27_object_system.md b/doc/JA/syntax/27_object_system.md index 787f68b27..2033db7c5 100644 --- a/doc/JA/syntax/27_object_system.md +++ b/doc/JA/syntax/27_object_system.md @@ -57,7 +57,7 @@ assert record.method() == 3 要求属性を定義し、オブジェクトを共通化するオブジェクトです。 大きく分けて多相型(Polymorphic Type)と単相型(Monomorphic Type)の2つがあります。典型的な単相型は`Int`, `Str`などで、多相型には`Option Int`, `[Int; 3]`などがあります。 -さらにオブジェクトの状態変更をするメソッドを定義した型は可変型(Mutable type)と呼ばれ、可変な属性に`!`をつける必要があります(e.g. 動的配列: `[T; !_]`)。 +さらにオブジェクトの状態変更をするメソッドを定義した型は可変型(Mutable type)と呼ばれ、可変な属性に`!`をつける必要があります(e.g. 動的リスト: `[T; !_]`)。 ## クラス diff --git a/doc/JA/syntax/28_pattern_matching.md b/doc/JA/syntax/28_pattern_matching.md index cfb65a511..92607cacf 100644 --- a/doc/JA/syntax/28_pattern_matching.md +++ b/doc/JA/syntax/28_pattern_matching.md @@ -64,8 +64,8 @@ name = match num: ```python,check_ignore # この2つは同じ -Array(T, N: {N | N >= 3}) -Array(T, N | N >= 3) +List(T, N: {N | N >= 3}) +List(T, N | N >= 3) f M, N | M >= 0, N >= 1 = ... f(1, 0) # TypeError: N (2nd parameter) must be 1 or more @@ -84,7 +84,7 @@ right(_, r) = r ### 可変長パターン -後述するタプル/配列/レコードパターンと組み合わせて使います。 +後述するタプル/リスト/レコードパターンと組み合わせて使います。 ```python,check_ignore [i, ...j] = [1, 2, 3, 4] @@ -104,7 +104,7 @@ m, n = 1, 2 f(x, y) = ... ``` -### 配列パターン +### リストパターン ```python,check_ignore [i, j] = [1, 2] diff --git a/doc/JA/syntax/29_comprehension.md b/doc/JA/syntax/29_comprehension.md index ecf39686f..de3e47453 100644 --- a/doc/JA/syntax/29_comprehension.md +++ b/doc/JA/syntax/29_comprehension.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/29_comprehension.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/29_comprehension.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) -`[expr | (name <- iterable)+ | (predicate)*]`で配列、 +`[expr | (name <- iterable)+ | (predicate)*]`でリスト、 `{expr | (name <- iterable)+ | (predicate)*}`でセット、 `{key: value | (name <- iterable)+ | (predicate)*}`でDictが作れます。 diff --git a/doc/JA/syntax/32_error_handling.md b/doc/JA/syntax/32_error_handling.md index 9ab544ba6..fc5bb3836 100644 --- a/doc/JA/syntax/32_error_handling.md +++ b/doc/JA/syntax/32_error_handling.md @@ -70,7 +70,7 @@ f() `Result`型はその利便性から他言語でも多く取り入れられていますが、例外機構と比較してエラーの発生元がわかりにくくなるというデメリットがあります。 そこで、Ergでは`Error`オブジェクトに`.stack`という属性を持たせており、擬似的に例外機構のようなスタックトレースを再現しています。 -`.stack`は呼び出し元オブジェクトの配列です。Errorオブジェクトは`return`(`?`によるものも含む)されるたびにその呼出元サブルーチンを`.stack`に積んでいきます。 +`.stack`は呼び出し元オブジェクトのリストです。Errorオブジェクトは`return`(`?`によるものも含む)されるたびにその呼出元サブルーチンを`.stack`に積んでいきます。 そして`return`ができないコンテクストで`?`されるなり`.unwrap`されるなりすると、トレースバックを表示しながらパニックします。 ```python,checker_ignore diff --git a/doc/JA/syntax/33_pipeline.md b/doc/JA/syntax/33_pipeline.md index 125505b20..4cd8dc5e1 100644 --- a/doc/JA/syntax/33_pipeline.md +++ b/doc/JA/syntax/33_pipeline.md @@ -19,14 +19,14 @@ log rand # 0.2597... 1+1*2 |>.times do log("a", end := "") # aaa -evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect Array +evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect List # パイプライン演算子を使わずに実装する場合、 -_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(Array) +_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(List) # または __evens = 1..100 \ .iter() \ .filter i -> i % 2 == 0 \ - .collect Array + .collect List ```

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 ``` +

Previous | Next -

\ 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.. U <: T (忘却規則) ``` -下のような配列は型として有効ではない。配列の要素は等質化されていることを強調するための意図的な設計である。 +下のようなリストは型として有効ではない。リストの要素は等質化されていることを強調するための意図的な設計である。 ```erg [Int, Str] diff --git a/doc/JA/syntax/type/advanced/erasure.md b/doc/JA/syntax/type/advanced/erasure.md index 436ea8ca8..a17cd424b 100644 --- a/doc/JA/syntax/type/advanced/erasure.md +++ b/doc/JA/syntax/type/advanced/erasure.md @@ -9,7 +9,7 @@ `[T; N]`型のオブジェクトはもちろん`[T; _]`型のメソッドを使用できますが、使用後`n`の情報は消去されます。長さが変わってしまっているかもしれないからです。長さが変わらないならばシグネチャで示さなくてはなりません。 ```python -# 配列の長さが変わらないことが保証される関数(sortなど) +# リストの長さが変わらないことが保証される関数(sortなど) f: [T; N] -> [T; N] # 長さが保障されない関数(filterなど) g: [T; n] -> [T; _] @@ -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はカインドを受け取る高階カインドのメソッド -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/JA/syntax/type/advanced/kind.md b/doc/JA/syntax/type/advanced/kind.md index eb2fc2ea7..9d05ca569 100644 --- a/doc/JA/syntax/type/advanced/kind.md +++ b/doc/JA/syntax/type/advanced/kind.md @@ -4,7 +4,7 @@ Ergでは全てが型付けられている。型自体も例外ではない。「型の型」を表すのが __カインド(種)__ である。例えば`1`が`Int`に属しているように、`Int`は`Type`に属している。`Type`は最もシンプルなカインドである __原子カインド(Atomic kind)__ である。型理論的の記法では、`Type`は`*`に対応する。 -カインドという概念で実用上重要なのは1項以上のカインド(多項カインド)である。1項のカインドは、例えば`Option`などがそれに属する。1項カインドは`Type -> Type`と表される[1](#1)。`Array`や`Option`などの __コンテナ__ は特に型を引数に取る多項カインドのことなのである。 +カインドという概念で実用上重要なのは1項以上のカインド(多項カインド)である。1項のカインドは、例えば`Option`などがそれに属する。1項カインドは`Type -> Type`と表される[1](#1)。`List`や`Option`などの __コンテナ__ は特に型を引数に取る多項カインドのことなのである。 `Type -> Type`という表記が示す通り、実は`Option`は`T`という型を受け取って`Option T`という型を返す関数である。ただし、この関数は通常の意味での関数ではないため、1項カインド(unary kind)と普通は呼称される。 なお、無名関数演算子である`->`自体も型を受け取って型を返す場合カインドとみることができる。 diff --git a/doc/JA/syntax/type/advanced/mut_struct.md b/doc/JA/syntax/type/advanced/mut_struct.md index d4e121391..d3e4e99db 100644 --- a/doc/JA/syntax/type/advanced/mut_struct.md +++ b/doc/JA/syntax/type/advanced/mut_struct.md @@ -28,7 +28,7 @@ v: [Str; 1]! ``` 可変構造型では可変化する型引数に`!`を付ける。上の場合は、`[Str; 0]!`型を`[Str; 1]!`型などに変更することができる。すなわち、長さを変更できる。 -因みに、`[T; N]!`型は`Array!(T, N)`型の糖衣構文である。 +因みに、`[T; N]!`型は`List!(T, N)`型の糖衣構文である。 可変構造型はもちろんユーザー定義も可能である。ただし、不変構造型とは構成法に関していくつか違いがあるので注意が必要である。 diff --git a/doc/JA/syntax/type/advanced/quantified_dependent.md b/doc/JA/syntax/type/advanced/quantified_dependent.md index 6c6c2528b..cb986abb6 100644 --- a/doc/JA/syntax/type/advanced/quantified_dependent.md +++ b/doc/JA/syntax/type/advanced/quantified_dependent.md @@ -6,7 +6,7 @@ Ergには量化型、依存型が存在します。すると当然、その二 ```python NonNullStr = |N: Nat| StrWithLen N | N != 0 # N: Nat; S: StrWithLen N; N != 0}と同じ -NonEmptyArray = |N: Nat| [_; N | N > 0] # N: Nat; A: Array(_, N); N > 0}と同じ +NonEmptyList = |N: Nat| [_; N | N > 0] # N: Nat; A: List(_, N); N > 0}と同じ ``` 量化依存型の標準形は`K(A, ... | Pred)`です。`K`は型構築子、`A, B`は型引数、`Pred`は条件式です。 diff --git a/doc/JA/syntax/type/advanced/variance.md b/doc/JA/syntax/type/advanced/variance.md index 3e45e77c0..2d18f7a2a 100644 --- a/doc/JA/syntax/type/advanced/variance.md +++ b/doc/JA/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 直感的に理解できることとして、 -* `s: Str`のとき`Array!(Object).push!(s)`はOK(`Str`を`Object`にアップキャストすれば良い) -* `o: Object`のとき`Array!(Str).push!(o)`はNG -* `Array!(Object).pop!().into(Str)`はNG -* `Array!(Str).pop!().into(Object)`はOK +* `s: Str`のとき`List!(Object).push!(s)`はOK(`Str`を`Object`にアップキャストすれば良い) +* `o: Object`のとき`List!(Str).push!(o)`はNG +* `List!(Object).pop!().into(Str)`はNG +* `List!(Str).pop!().into(Object)`はOK である。これは、型システム的には @@ -82,7 +82,7 @@ List(T). ## 変性指定 `List T`の例については注意が必要なので、もう少し詳しく説明します。 -上のコードを理解するためには多相型の変性について知っておく必要があります。変性については[この項](./variance.md)で詳しく解説していますが、さしあたって必要となる事実は以下の3つです: +上のコードを理解するためには多相型の変性について知っておく必要があります。変性については[この項](./variance.md)で詳しく解説していますが、さしあたって必要となる事実は以下の3つです: * 通常の多相型、`List T`などは`T`に対して共変(`U > T`のとき`List U > List T`) * 関数`T -> U`は引数型`T`に対して反変(`S > T`のとき`(S -> U) < (T -> U)`) diff --git a/doc/JA/terms.md b/doc/JA/terms.md index b5c057be6..cc09bfea8 100644 --- a/doc/JA/terms.md +++ b/doc/JA/terms.md @@ -292,7 +292,7 @@ Ergにおいては、基本オブジェクトと同等。コンパイル時に ### [依存型](../syntax/type/dependent_type.md) -値(慣用的には、型ではない)を引数にとる型。例として、`Array(T, N)`は第二引数に`Nat`型の値を受け取る依存型である。 +値(慣用的には、型ではない)を引数にとる型。例として、`List(T, N)`は第二引数に`Nat`型の値を受け取る依存型である。 ### イミュータブル -> [不変] @@ -483,7 +483,7 @@ Erg標準APIのうち、.erファイル内で実装されていないAPI。 ### コメント -### [コレクション](../syntax/10_array.md) +### [コレクション](../syntax/10_list.md) ### コロン -> [:] @@ -600,7 +600,7 @@ Ergプログラムが記述されたファイル。 ### スプレッド演算子 -> [展開代入] -### [スライス](../syntax/10_array.md#スライス) +### [スライス](../syntax/10_list.md#スライス) `x[a..b]`の形式で生成される、配列の部分列を表すオブジェクト。 @@ -754,7 +754,7 @@ f x = ... ## は行 -### [配列](../syntax/10_array.md) +### [配列](../syntax/10_list.md) ### [派生型](../syntax/type/variances.md/#ユーザー定義型の変性) diff --git a/doc/JA/unify_terms.md b/doc/JA/unify_terms.md index 4236db213..df0cad038 100644 --- a/doc/JA/unify_terms.md +++ b/doc/JA/unify_terms.md @@ -75,11 +75,6 @@ Attribute、属性を使用する。 サブルーチンオブジェクトに引数を与えて結果を得ること。 呼び出し(Call)を使用する。Applicationは「応用ソフトウェア」の用法があるためである。 -## 配列(Array)、リスト(List) - -Arrayを使用する。Ergの配列は(一般的には)メモリ上で連続的に配置されるからである。 -Listはいわゆる連結リスト、またはPythonのデータ型としてのリストを指すこととする。 - ## プロシージャ、手続き プロシージャに統一する。サブルーチンは関数(と演算子)、プロシージャ、メソッドの総称。Callableはさらに`__call__`を実装しているものすべて。 @@ -103,4 +98,4 @@ Listはいわゆる連結リスト、またはPythonのデータ型としての ## スーパータイピング、汎化型付け、上位型付け -汎化型付けを使用する。 \ No newline at end of file +汎化型付けを使用する。 diff --git a/doc/zh_CN/API/funcs.md b/doc/zh_CN/API/funcs.md index 97afcd53c..6a6e551b5 100644 --- a/doc/zh_CN/API/funcs.md +++ b/doc/zh_CN/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_CN/API/modules/repl.md b/doc/zh_CN/API/modules/repl.md index 0441fc6d3..37f231ec9 100644 --- a/doc/zh_CN/API/modules/repl.md +++ b/doc/zh_CN/API/modules/repl.md @@ -22,5 +22,5 @@ ```python 1.guess((1,), 2) # -[1, 2].guess((3, 4), [1, 2, 3, 4]) # -``` \ No newline at end of file +[1, 2].guess((3, 4), [1, 2, 3, 4]) # +``` diff --git a/doc/zh_CN/API/types/classes/Array!(T,N).md b/doc/zh_CN/API/types/classes/List!(T,N).md similarity index 65% rename from doc/zh_CN/API/types/classes/Array!(T,N).md rename to doc/zh_CN/API/types/classes/List!(T,N).md index 89e0c29e4..ec3786243 100644 --- a/doc/zh_CN/API/types/classes/Array!(T,N).md +++ b/doc/zh_CN/API/types/classes/List!(T,N).md @@ -1,6 +1,6 @@ -# Array! T: Type, N: Nat +# List! T: Type, N: Nat -[![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/API/types/classes/Array!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) +[![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/API/types/classes/List!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) 在编译时知道长度的可变长度数组。`[T; N]!`也有语法糖。 diff --git a/doc/zh_CN/API/types/classes/Array(T,N).md b/doc/zh_CN/API/types/classes/List(T,N).md similarity index 70% rename from doc/zh_CN/API/types/classes/Array(T,N).md rename to doc/zh_CN/API/types/classes/List(T,N).md index ed20fbe57..b3660465e 100644 --- a/doc/zh_CN/API/types/classes/Array(T,N).md +++ b/doc/zh_CN/API/types/classes/List(T,N).md @@ -1,6 +1,6 @@ -# Array T: Type, N: Nat +# List T: Type, N: Nat -[![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/API/types/classes/Array(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) +[![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/API/types/classes/List(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) `[T; N]` 是语法法糖. `N` 可以发出 (`[T; _]`). @@ -25,7 +25,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}] 返回对象的出现频率 diff --git a/doc/zh_CN/API/types/classes/ArrayWithLen(T,N).md b/doc/zh_CN/API/types/classes/ListWithLen(T,N).md similarity index 61% rename from doc/zh_CN/API/types/classes/ArrayWithLen(T,N).md rename to doc/zh_CN/API/types/classes/ListWithLen(T,N).md index cf5a64036..485e2d4fb 100644 --- a/doc/zh_CN/API/types/classes/ArrayWithLen(T,N).md +++ b/doc/zh_CN/API/types/classes/ListWithLen(T,N).md @@ -1,8 +1,8 @@ -# ArrayWithLen T: Type, N: Nat +# ListWithLen T: Type, N: Nat -[![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/API/types/classes/ArrayWithLen(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ArrayWithLen(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) +[![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/API/types/classes/ListWithLen(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ListWithLen(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) -`[T; N]`是语法糖。还有一个[`Array` 类型](../../../syntax/10_array.md)省略了长度 +`[T; N]`是语法糖。还有一个[`List` 类型](../../../syntax/10_list.md)省略了长度 ## 方法 @@ -25,7 +25,7 @@ assert ["a", "b", "c", "d", "e"].values_at([0, 1, 3]) == ["a", "b", "d"] assert all(False for _ in []) ``` -## ArrayWithLen T, N | T <: Eq 的方法 +## ListWithLen T, N | T <: Eq 的方法 * freq self -> [{T: Nat}] 返回对象出现的次数 diff --git a/doc/zh_CN/API/types/classes/ArrayWithMutLength!(T,N).md b/doc/zh_CN/API/types/classes/ListWithMutLength!(T,N).md similarity index 60% rename from doc/zh_CN/API/types/classes/ArrayWithMutLength!(T,N).md rename to doc/zh_CN/API/types/classes/ListWithMutLength!(T,N).md index 376fab5a7..8558249f7 100644 --- a/doc/zh_CN/API/types/classes/ArrayWithMutLength!(T,N).md +++ b/doc/zh_CN/API/types/classes/ListWithMutLength!(T,N).md @@ -1,8 +1,8 @@ -# ArrayWithMutLength! T: Type, N: Nat! +# ListWithMutLength! T: Type, N: Nat! -[![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/API/types/classes/ArrayWithMutLength!(T,N).md%26commit_hash%3D06f8edc9e2c0cee34f6396fd7c64ec834ffb5352)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ArrayWithMutLength!(T,N).md&commit_hash=06f8edc9e2c0cee34f6396fd7c64ec834ffb5352) +[![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/API/types/classes/ListWithMutLength!(T,N).md%26commit_hash%3D06f8edc9e2c0cee34f6396fd7c64ec834ffb5352)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ListWithMutLength!(T,N).md&commit_hash=06f8edc9e2c0cee34f6396fd7c64ec834ffb5352) -一个可变长度数组,其长度在编译时已知。还有语法糖`ArrayWithMutLength(T, !N) == [T; !N]` +一个可变长度数组,其长度在编译时已知。还有语法糖`ListWithMutLength(T, !N) == [T; !N]` ## 方法 diff --git a/doc/zh_CN/compiler/hir.md b/doc/zh_CN/compiler/hir.md index 3a13eaa2b..877455f58 100644 --- a/doc/zh_CN/compiler/hir.md +++ b/doc/zh_CN/compiler/hir.md @@ -13,7 +13,7 @@ for! 0..10, i => log v.sum() ``` -从此代码生成的 AST 如下所示: +从此代码生成的 AST 如下所示: ```python AST(Module[ @@ -26,7 +26,7 @@ AST(Module[ body: Block[ UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), }, ], }, @@ -70,7 +70,7 @@ AST(Module[ ]) ``` -从 AST 生成的 HIR 如下所示: +从 AST 生成的 HIR 如下所示: ```python HIR(Module[ @@ -83,7 +83,7 @@ HIR(Module[ body: Block[ expr: UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), t: [0..10, 0]!, }, ], diff --git a/doc/zh_CN/compiler/inference.md b/doc/zh_CN/compiler/inference.md index 47968ce34..c6b9a40cb 100644 --- a/doc/zh_CN/compiler/inference.md +++ b/doc/zh_CN/compiler/inference.md @@ -40,19 +40,19 @@ Erg 的类型推断主要使用 Hindley-Milner 类型推断算法(尽管已经 第 1 行。Def{sig: v, block: ![]} 获取块类型: 获取 UnaryOp 类型: - getArray 类型: `['T; 0]` + getList 类型: `['T; 0]` 实例化: `[?T; 0]` (替代,评估被省略) 更新: `Γ: {v: [?T; 0]!}` 表达式 返回`NoneType`: OK 第 2 行 CallMethod {obj: v, name: push!, args: [1]} - 获取 obj 类型: `Array!(?T, 0)` - 搜索: `Γ Array!(?T, 0).push!({1})` - 得到: `= Array!('T ~> 'T, 'N ~> 'N+1).push!('T) => NoneType` - 实例化: `Array!(?T, ?N).push!(?T) => NoneType` - 替代(`S: {?T --> Nat, ?N --> 0}`): `Array!(Nat ~> Nat, 0 ~> 0+1).push!(Nat) => NoneType` - 评估: `Array!(Nat, 0 ~> 1).push!({1}) => NoneType` + 获取 obj 类型: `List!(?T, 0)` + 搜索: `Γ List!(?T, 0).push!({1})` + 得到: `= List!('T ~> 'T, 'N ~> 'N+1).push!('T) => NoneType` + 实例化: `List!(?T, ?N).push!(?T) => NoneType` + 替代(`S: {?T --> Nat, ?N --> 0}`): `List!(Nat ~> Nat, 0 ~> 0+1).push!(Nat) => NoneType` + 评估: `List!(Nat, 0 ~> 1).push!({1}) => NoneType` 更新: `Γ: {v: [Nat; 1]!}` 表达式 返回`NoneType`: OK diff --git a/doc/zh_CN/compiler/parsing.md b/doc/zh_CN/compiler/parsing.md index afa0014e2..5494c1759 100644 --- a/doc/zh_CN/compiler/parsing.md +++ b/doc/zh_CN/compiler/parsing.md @@ -22,8 +22,8 @@ f(1,) == f(1) 右值中甚至可以有左值 ```python -# i 是左值,Array(Int) 和 [1, 2, 3] 是右值 -i: Array(Int) = [1, 2, 3] +# i 是左值,List(Int) 和 [1, 2, 3] 是右值 +i: List(Int) = [1, 2, 3] # `[1, 2, 3].iter().map i -> i + 1`是右值,但是`->`左边的i是左值 a = [1, 2, 3].iter().map i -> i + 1 # {x = 1; y = 2} 是右值,但 `x`, `y` 是左值 diff --git a/doc/zh_CN/syntax/01_literal.md b/doc/zh_CN/syntax/01_literal.md index 67dd3779d..cc3d6086b 100644 --- a/doc/zh_CN/syntax/01_literal.md +++ b/doc/zh_CN/syntax/01_literal.md @@ -72,7 +72,7 @@ assert 1e-10 == 0.0000000001 这些文字中的每一个都有自己的文档分别描述它们,因此请参阅该文档以获取详细信息 -### [数组字面量](./10_array.md) +### [数组字面量](./10_list.md) ```python [], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ... @@ -102,7 +102,7 @@ assert 1e-10 == 0.0000000001 {}, {1}, {1, 2, 3}, {"1", "2", "1"}, {1, "1", True, [1]} ... ``` -与 `Array` 字面量不同的是,`Set` 中删除了重复元素 +与 `List` 字面量不同的是,`Set` 中删除了重复元素 ```python assert {1, 2, 1} == {1, 2} diff --git a/doc/zh_CN/syntax/09_builtin_procs.md b/doc/zh_CN/syntax/09_builtin_procs.md index 9267ac6f2..c19fc8fba 100644 --- a/doc/zh_CN/syntax/09_builtin_procs.md +++ b/doc/zh_CN/syntax/09_builtin_procs.md @@ -12,5 +12,5 @@ ```

- 上一页 | 下一页 + 上一页 | 下一页

diff --git a/doc/zh_CN/syntax/10_array.md b/doc/zh_CN/syntax/10_list.md similarity index 81% rename from doc/zh_CN/syntax/10_array.md rename to doc/zh_CN/syntax/10_list.md index f625757ad..83d03c056 100644 --- a/doc/zh_CN/syntax/10_array.md +++ b/doc/zh_CN/syntax/10_list.md @@ -1,6 +1,6 @@ # 数组 -[![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) 数组是最基本的__collection(聚合)__ 集合是一个可以在其中包含多个对象的对象 diff --git a/doc/zh_CN/syntax/11_dict.md b/doc/zh_CN/syntax/11_dict.md index 58d7ab28d..b5508df07 100644 --- a/doc/zh_CN/syntax/11_dict.md +++ b/doc/zh_CN/syntax/11_dict.md @@ -2,7 +2,6 @@ [![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/11_dict.md%26commit_hash%3De598201a939e24a41d3c26a828fdee01ad18eaf8)](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/11_dict.md&commit_hash=e598201a939e24a41d3c26a828fdee01ad18eaf8) - Dict 是键/值对的集合 ```python @@ -66,5 +65,5 @@ valid2: {Int: Int or Str} = {1: "a", 2: 2} ```

- 上一页 | 下一页 + 上一页 | 下一页

diff --git a/doc/zh_CN/syntax/17_iterator.md b/doc/zh_CN/syntax/17_iterator.md index 310401269..004f06664 100644 --- a/doc/zh_CN/syntax/17_iterator.md +++ b/doc/zh_CN/syntax/17_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() # <数组迭代器对象> log (1..3).iter() # ``` -`ArrayIterator` 和 `RangeIterator` 都是实现 `Iterator` 的类,它们的存在只是为了提供 `Array` 和 `Range` 迭代函数 +`ListIterator` 和 `RangeIterator` 都是实现 `Iterator` 的类,它们的存在只是为了提供 `List` 和 `Range` 迭代函数 这种设计模式称为伴生类 [1](#1) -而"IteratorImpl"补丁是迭代功能的核心。`Iterator` 只需要一个`.next` 方法,`IteratorImpl` 确实提供了几十种方法。`ArrayIterator`和`RangeIterator`只需实现`.next`方法就可以使用`IteratorImpl`的实现方法。为了方便起见,标准库实现了许多迭代器 +而"IteratorImpl"补丁是迭代功能的核心。`Iterator` 只需要一个`.next` 方法,`IteratorImpl` 确实提供了几十种方法。`ListIterator`和`RangeIterator`只需实现`.next`方法就可以使用`IteratorImpl`的实现方法。为了方便起见,标准库实现了许多迭代器 ```mermaid classDiagram - class Array~T~ { + class List~T~ { ... - iter() ArrayIterator~T~ + iter() ListIterator~T~ } class Range~T~ { ... @@ -59,10 +59,10 @@ classDiagram <> iter() Iterator~T~ } - Iterable~T~ <|.. Array~T~: Impl + Iterable~T~ <|.. List~T~: Impl Iterable~T~ <|.. Range~T~: Impl - class ArrayIterator~T~ { - array: Array~T~ + class ListIterator~T~ { + array: List~T~ next() T } class RangeIterator~T~ { @@ -73,10 +73,10 @@ classDiagram <> next() T } - Iterator~T~ <|.. ArrayIterator~T~: Impl + Iterator~T~ <|.. ListIterator~T~: Impl Iterator~T~ <|.. RangeIterator~T~: Impl - Array <-- ArrayIterator + List <-- ListIterator Range <-- RangeIterator ``` diff --git a/doc/zh_CN/syntax/20_visibility.md b/doc/zh_CN/syntax/20_visibility.md index d6364ad74..ecaa447c6 100644 --- a/doc/zh_CN/syntax/20_visibility.md +++ b/doc/zh_CN/syntax/20_visibility.md @@ -189,5 +189,5 @@ _ = foo.record.a.z # OK ```

- 上一页 | 下一页 -

\ No newline at end of file + 上一页 | 下一页 +

diff --git a/doc/zh_CN/syntax/21_naming_rule.md b/doc/zh_CN/syntax/21_naming_rule.md index bbd1af899..979710779 100644 --- a/doc/zh_CN/syntax/21_naming_rule.md +++ b/doc/zh_CN/syntax/21_naming_rule.md @@ -1,6 +1,6 @@ # 命名规定 -[![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/21_naming_rule.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/21_naming_rule.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) +[![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/22_naming_rule.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/22_naming_rule.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) 如果要将变量用作常量表达式,请确保它以大写字母开头。两个或多个字母可能是小写的 @@ -49,4 +49,4 @@ bar! = pyimport("foo").'bar'

上一页 | 下一页 -

\ No newline at end of file +

diff --git a/doc/zh_CN/syntax/22_lambda.md b/doc/zh_CN/syntax/22_lambda.md index aea9dd24e..c904ce471 100644 --- a/doc/zh_CN/syntax/22_lambda.md +++ b/doc/zh_CN/syntax/22_lambda.md @@ -93,5 +93,5 @@ id = |T| x: T -> x ```

- 上一页 | 下一页 -

\ No newline at end of file + 上一页 | 下一页 +

diff --git a/doc/zh_CN/syntax/27_pattern_matching.md b/doc/zh_CN/syntax/27_pattern_matching.md index 3d7e9c9ee..e9a226193 100644 --- a/doc/zh_CN/syntax/27_pattern_matching.md +++ b/doc/zh_CN/syntax/27_pattern_matching.md @@ -25,7 +25,7 @@ fn: Int -> Int = x -> x + 1 # 高阶类型 a: [Int; 4] = [0, 1, 2, 3] # or -a: Array Int, 4 = [0, 1, 2, 3] +a: List Int, 4 = [0, 1, 2, 3] ``` ### 文字字面量 @@ -68,8 +68,8 @@ name = match num: ```python,checker_ignore # 这两个是一样的 -Array(T, N: {N | N >= 3}) -Array(T, N | N >= 3) +List(T, N: {N | N >= 3}) +List(T, N | N >= 3) f M, N | M >= 0, N >= 1 = ... f(1, 0) # 类型错误: N(第二个参数)必须为 1 或更多 diff --git a/doc/zh_CN/syntax/28_comprehension.md b/doc/zh_CN/syntax/28_comprehension.md index 2a3f7a497..9d64a3e02 100644 --- a/doc/zh_CN/syntax/28_comprehension.md +++ b/doc/zh_CN/syntax/28_comprehension.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/28_comprehension.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/28_comprehension.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) -Array和`[expr | (name <- iterable)+ (predicate)*]`, +List和`[expr | (name <- iterable)+ (predicate)*]`, set和`{expr | (name <- iterable)+ (predicate)*}`, 你可以创建一个字典`{key: value | (name <- iterable)+ (predicate)*}`. diff --git a/doc/zh_CN/syntax/30_decorator.md b/doc/zh_CN/syntax/30_decorator.md index f5f65a943..bbe2b5350 100644 --- a/doc/zh_CN/syntax/30_decorator.md +++ b/doc/zh_CN/syntax/30_decorator.md @@ -118,5 +118,5 @@ assert Y in U. attaches 表示这是一个测试子例程。测试子程序使用`erg test`命令运行

- 上一页 | 下一页 + 上一页 | 下一页

diff --git a/doc/zh_CN/syntax/31_error_handling.md b/doc/zh_CN/syntax/31_error_handling.md index 7509ebd99..cf0311a4c 100644 --- a/doc/zh_CN/syntax/31_error_handling.md +++ b/doc/zh_CN/syntax/31_error_handling.md @@ -1,6 +1,6 @@ # 错误处理系统 -[![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/31_error_handling.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/31_error_handling.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) +[![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/32_error_handling.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/32_error_handling.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) 主要使用Result类型 在Erg中,如果您丢弃Error类型的对象(顶层不支持),则会发生错误 @@ -108,4 +108,4 @@ panic "something went wrong!"

上一页 | 下一页 -

\ No newline at end of file +

diff --git a/doc/zh_CN/syntax/32_pipeline.md b/doc/zh_CN/syntax/32_pipeline.md index 4422c566e..3fdf2fd6b 100644 --- a/doc/zh_CN/syntax/32_pipeline.md +++ b/doc/zh_CN/syntax/32_pipeline.md @@ -19,16 +19,16 @@ log rand # 0.2597... 1+1*2 |>.times do log("a", end := "") # aaa -evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect Array +evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect List # 在没有管道操作符的情况下实现, -_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(Array) +_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(List) # or __evens = 1..100 \ .iter() \ .filter i -> i % 2 == 0 \ - .collect Array + .collect List ```

- 上一页 | 下一页 + 上一页 | 下一页

diff --git a/doc/zh_CN/syntax/SUMMARY.md b/doc/zh_CN/syntax/SUMMARY.md index 1bd3499fc..bb04f0f49 100644 --- a/doc/zh_CN/syntax/SUMMARY.md +++ b/doc/zh_CN/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) @@ -65,7 +65,7 @@ - [可变性](./18_mutability.md) - [所有权](./19_ownership.md) - [可见性](./20_visibility.md) -- [命名规定](./21_naming_rule.md) +- [命名规定](./22_naming_rule.md) - [Lambda](./22_lambda.md) - [子程序](./23_subroutine.md) - [闭包](./24_closure.md) @@ -75,7 +75,7 @@ - [推导式](./28_comprehension.md) - [扩展语法](./29_spread_syntax.md) - [装饰器](./30_decorator.md) -- [错误处理系统](./31_error_handling.md) +- [错误处理系统](./32_error_handling.md) - [管道运算符](./32_pipeline.md) - [与 Python 集成](./33_integration_with_Python.md) - [包系统](./34_package_system.md) diff --git a/doc/zh_CN/syntax/indexes.md b/doc/zh_CN/syntax/indexes.md index 46c4f0d38..7ec6aa530 100644 --- a/doc/zh_CN/syntax/indexes.md +++ b/doc/zh_CN/syntax/indexes.md @@ -54,7 +54,7 @@ * >> * >= * @ → [decorator](./29_decorator.md) -* [] → [Array](./10_array.md) +* [] → [List](./10_list.md) * \ → [Indention](./00_basic.md) * \ → [Str](./01_literal.md) * ^ @@ -85,7 +85,7 @@ * [anonymous function](./21_lambda.md) * [Anonymous polycorrelation coefficient](./21_lambda.md) * anonymous type → [Type System](./type/01_type_system.md) -* [Array](./10_array.md) +* [List](./10_list.md) * [assert] * [Attach](./29_decorator.md) * [attribute](type/09_attributive.md) diff --git a/doc/zh_CN/syntax/type/01_type_system.md b/doc/zh_CN/syntax/type/01_type_system.md index cb9f36b59..f0a06808b 100644 --- a/doc/zh_CN/syntax/type/01_type_system.md +++ b/doc/zh_CN/syntax/type/01_type_system.md @@ -47,14 +47,14 @@ Erg 的类型系统包含结构子类型 (SST)。该系统类型化的类型称 整个名义类型的类型(`NominalType`)和整个结构类型的类型(`StructuralType`)是整个类型(`Type`)的类型的子类型 -Erg 可以将参数(类型参数)传递给类型定义。带有类型参数的 `Option`、`Array` 等称为多项式类型。这些本身不是类型,但它们通过应用参数成为类型。诸如 `Int`、`Str` 等没有参数的类型称为简单类型(标量类型) +Erg 可以将参数(类型参数)传递给类型定义。带有类型参数的 `Option`、`List` 等称为多项式类型。这些本身不是类型,但它们通过应用参数成为类型。诸如 `Int`、`Str` 等没有参数的类型称为简单类型(标量类型) 一个类型可以看成一个集合,并且存在包含关系。例如,"Num"包含"Add"、"Sub"等,"Int"包含"Nat" 所有类的上类是`Object == Class {:}`,所有类型的下类是`Never == Class {}`。这在下面描述 ## 类型 -像 `Array T` 这样的类型可以看作是 `Type -> Type` 类型的函数,它以 `T` 类型为参数并返回 `Array T` 类型(在类型论中也称为 Kind)。像 `Array T` 这样的类型专门称为多态类型,而 `Array` 本身称为一元 Kind +像 `List T` 这样的类型可以看作是 `Type -> Type` 类型的函数,它以 `T` 类型为参数并返回 `List T` 类型(在类型论中也称为 Kind)。像 `List T` 这样的类型专门称为多态类型,而 `List` 本身称为一元 Kind 已知参数和返回类型的函数的类型表示为`(T, U) -> V`。如果要指定同一类型的整个双参数函数,可以使用 `|T| (T, T) -> T`,如果要指定整个 N 参数函数,可以使用 `Func N`。但是,`Func N` 类型没有关于参数数量或其类型的信息,因此所有返回值在调用时都是`Obj` 类型 @@ -62,7 +62,7 @@ Erg 可以将参数(类型参数)传递给类型定义。带有类型参数的 ` `Method` 类型是一个函数/过程,其第一个参数是它所属的对象 `self`(通过引用)。对于依赖类型,也可以在应用方法后指定自己的类型。这是 `T!(!N)` 类型和 `T!(N ~> N-1)。() => Int` 等等 -Erg 的数组(Array)就是 Python 所说的列表。`[诠释; 3]`是一个数组类,包含三个`Int`类型的对象 +Erg 的数组(List)就是 Python 所说的列表。`[诠释; 3]`是一个数组类,包含三个`Int`类型的对象 > __Note__: `(Type; N)` 既是类型又是值,所以可以这样使用 > @@ -115,7 +115,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/zh_CN/syntax/type/02_basic.md b/doc/zh_CN/syntax/type/02_basic.md index ce828cb03..b50340523 100644 --- a/doc/zh_CN/syntax/type/02_basic.md +++ b/doc/zh_CN/syntax/type/02_basic.md @@ -24,11 +24,11 @@ f([1, "a"]: [Int or Str]) ```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 # 大写变量的值必须是常量表达式 @@ -133,7 +133,7 @@ C:: Id = Int Point3D = {x = Int; y = Int; z = Int} IorS = Int or Str -Vector = Array Int +Vector = List Int ``` 此外,当显示错误时,如果定义了复合类型(在上面的示例中,右侧类型不是第一个类型),编译器将为它们使用别名 @@ -146,8 +146,8 @@ Vector = Array Int Id = Int UserId = Int # 类型警告: 重复别名: Id 和 UserId -Ids = Array Id -Ints = Array Int # 类型警告: 重复别名: Isd 和 Ints +Ids = List Id +Ints = List Int # 类型警告: 重复别名: Isd 和 Ints IorS = Int or Str IorSorB = IorS or Bool diff --git a/doc/zh_CN/syntax/type/03_trait.md b/doc/zh_CN/syntax/type/03_trait.md index 7d4822929..2628c070a 100644 --- a/doc/zh_CN/syntax/type/03_trait.md +++ b/doc/zh_CN/syntax/type/03_trait.md @@ -44,7 +44,7 @@ Trait 也是一种类型,因此可以用于普通类型规范 ```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包含 @@ -117,11 +117,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"]. ``` ## OverrideTrait @@ -181,7 +181,7 @@ print! P|<: Mul(Int)|.Output # ## 附录: 与 Rust Trait的区别 -Erg 的Trait忠实于 [Schärli 等人] (https://www.ptidej.net/courses/ift6251/fall06/presentations/061122/061122.doc.pdf) 提出的Trait +Erg 的Trait忠实于 [Schärli 等人] () 提出的Trait 为了允许代数运算,Trait被设计为不能有方法实现目录,但可以在必要时进行修补

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) # -[1, 2].guess((3, 4), [1, 2, 3, 4]) # -``` \ No newline at end of file +[1, 2].guess((3, 4), [1, 2, 3, 4]) # +``` diff --git a/doc/zh_TW/API/types/classes/Array!(T,N).md b/doc/zh_TW/API/types/classes/List!(T,N).md similarity index 65% rename from doc/zh_TW/API/types/classes/Array!(T,N).md rename to doc/zh_TW/API/types/classes/List!(T,N).md index 1a1dab7d1..f1ac0423c 100644 --- a/doc/zh_TW/API/types/classes/Array!(T,N).md +++ b/doc/zh_TW/API/types/classes/List!(T,N).md @@ -1,6 +1,6 @@ -# Array! T: Type, N: Nat +# List! T: Type, N: Nat -[![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/API/types/classes/Array!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) +[![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/API/types/classes/List!(T,N).md%26commit_hash%3Dcee3820a85d8a9dbdd1e506e6adc59eab5e19da1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List!(T,N).md&commit_hash=cee3820a85d8a9dbdd1e506e6adc59eab5e19da1) 在編譯時知道長度的可變長度數組。`[T; N]!`也有語法糖。 diff --git a/doc/zh_TW/API/types/classes/Array(T,N).md b/doc/zh_TW/API/types/classes/List(T,N).md similarity index 70% rename from doc/zh_TW/API/types/classes/Array(T,N).md rename to doc/zh_TW/API/types/classes/List(T,N).md index c943970e4..c5dd56f9e 100644 --- a/doc/zh_TW/API/types/classes/Array(T,N).md +++ b/doc/zh_TW/API/types/classes/List(T,N).md @@ -1,6 +1,6 @@ -# Array T: Type, N: Nat +# List T: Type, N: Nat -[![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/API/types/classes/Array(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/Array(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) +[![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/API/types/classes/List(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/List(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) `[T; N]` 是語法法糖. `N` 可以發出 (`[T; _]`). @@ -25,7 +25,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}] 返回對象的出現頻率 diff --git a/doc/zh_TW/API/types/classes/ArrayWithLen(T,N).md b/doc/zh_TW/API/types/classes/ListWithLen(T,N).md similarity index 61% rename from doc/zh_TW/API/types/classes/ArrayWithLen(T,N).md rename to doc/zh_TW/API/types/classes/ListWithLen(T,N).md index fb5489c5b..e70450891 100644 --- a/doc/zh_TW/API/types/classes/ArrayWithLen(T,N).md +++ b/doc/zh_TW/API/types/classes/ListWithLen(T,N).md @@ -1,8 +1,8 @@ -# ArrayWithLen T: Type, N: Nat +# ListWithLen T: Type, N: Nat -[![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/API/types/classes/ArrayWithLen(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ArrayWithLen(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) +[![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/API/types/classes/ListWithLen(T,N).md%26commit_hash%3D13f2d31aee9012f60b7a40d4b764921f1419cdfe)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ListWithLen(T,N).md&commit_hash=13f2d31aee9012f60b7a40d4b764921f1419cdfe) -`[T; N]`是語法糖。還有一個[`Array` 類型](../../../syntax/10_array.md)省略了長度 +`[T; N]`是語法糖。還有一個[`List` 類型](../../../syntax/10_list.md)省略了長度 ## 方法 @@ -25,7 +25,7 @@ assert ["a", "b", "c", "d", "e"].values_at([0, 1, 3]) == ["a", "b", "d"] assert all(False for _ in []) ``` -## ArrayWithLen T, N | T <: Eq 的方法 +## ListWithLen T, N | T <: Eq 的方法 * freq self -> [{T: Nat}] 返回對象出現的次數 diff --git a/doc/zh_TW/API/types/classes/ArrayWithMutLength!(T,N).md b/doc/zh_TW/API/types/classes/ListWithMutLength!(T,N).md similarity index 60% rename from doc/zh_TW/API/types/classes/ArrayWithMutLength!(T,N).md rename to doc/zh_TW/API/types/classes/ListWithMutLength!(T,N).md index 47e045bc5..70e3db9d2 100644 --- a/doc/zh_TW/API/types/classes/ArrayWithMutLength!(T,N).md +++ b/doc/zh_TW/API/types/classes/ListWithMutLength!(T,N).md @@ -1,8 +1,8 @@ -# ArrayWithMutLength! T: Type, N: Nat! +# ListWithMutLength! T: Type, N: Nat! -[![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/API/types/classes/ArrayWithMutLength!(T,N).md%26commit_hash%3D06f8edc9e2c0cee34f6396fd7c64ec834ffb5352)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ArrayWithMutLength!(T,N).md&commit_hash=06f8edc9e2c0cee34f6396fd7c64ec834ffb5352) +[![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/API/types/classes/ListWithMutLength!(T,N).md%26commit_hash%3D06f8edc9e2c0cee34f6396fd7c64ec834ffb5352)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/types/classes/ListWithMutLength!(T,N).md&commit_hash=06f8edc9e2c0cee34f6396fd7c64ec834ffb5352) -一個可變長度數組,其長度在編譯時已知。還有語法糖`ArrayWithMutLength(T, !N) == [T; !N]` +一個可變長度數組,其長度在編譯時已知。還有語法糖`ListWithMutLength(T, !N) == [T; !N]` ## 方法 diff --git a/doc/zh_TW/compiler/hir.md b/doc/zh_TW/compiler/hir.md index ef7c23af6..76d1f0cd1 100644 --- a/doc/zh_TW/compiler/hir.md +++ b/doc/zh_TW/compiler/hir.md @@ -13,7 +13,7 @@ for! 0..10, i => log v.sum() ``` -從此代碼生成的 AST 如下所示: +從此代碼生成的 AST 如下所示: ```python AST(Module[ @@ -26,7 +26,7 @@ AST(Module[ body: Block[ UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), }, ], }, @@ -70,7 +70,7 @@ AST(Module[ ]) ``` -從 AST 生成的 HIR 如下所示: +從 AST 生成的 HIR 如下所示: ```python HIR(Module[ @@ -83,7 +83,7 @@ HIR(Module[ body: Block[ expr: UnaryOp{ op: "!", - expr: Array([]), + expr: List([]), t: [0..10, 0]!, }, ], diff --git a/doc/zh_TW/compiler/inference.md b/doc/zh_TW/compiler/inference.md index de01b8c92..cc9753c66 100644 --- a/doc/zh_TW/compiler/inference.md +++ b/doc/zh_TW/compiler/inference.md @@ -40,19 +40,19 @@ Erg 的類型推斷主要使用 Hindley-Milner 類型推斷算法(盡管已經 第 1 行。Def{sig: v, block: ![]} 獲取塊類型: 獲取 UnaryOp 類型: - getArray 類型: `['T; 0]` + getList 類型: `['T; 0]` 實例化: `[?T; 0]` (替代,評估被省略) 更新: `Γ: {v: [?T; 0]!}` 表達式 返回`NoneType`: OK 第 2 行 CallMethod {obj: v, name: push!, args: [1]} - 獲取 obj 類型: `Array!(?T, 0)` - 搜索: `Γ Array!(?T, 0).push!({1})` - 得到: `= Array!('T ~> 'T, 'N ~> 'N+1).push!('T) => NoneType` - 實例化: `Array!(?T, ?N).push!(?T) => NoneType` - 替代(`S: {?T --> Nat, ?N --> 0}`): `Array!(Nat ~> Nat, 0 ~> 0+1).push!(Nat) => NoneType` - 評估: `Array!(Nat, 0 ~> 1).push!({1}) => NoneType` + 獲取 obj 類型: `List!(?T, 0)` + 搜索: `Γ List!(?T, 0).push!({1})` + 得到: `= List!('T ~> 'T, 'N ~> 'N+1).push!('T) => NoneType` + 實例化: `List!(?T, ?N).push!(?T) => NoneType` + 替代(`S: {?T --> Nat, ?N --> 0}`): `List!(Nat ~> Nat, 0 ~> 0+1).push!(Nat) => NoneType` + 評估: `List!(Nat, 0 ~> 1).push!({1}) => NoneType` 更新: `Γ: {v: [Nat; 1]!}` 表達式 返回`NoneType`: OK diff --git a/doc/zh_TW/compiler/parsing.md b/doc/zh_TW/compiler/parsing.md index c6d9a3a49..9c195957a 100644 --- a/doc/zh_TW/compiler/parsing.md +++ b/doc/zh_TW/compiler/parsing.md @@ -22,8 +22,8 @@ f(1,) == f(1) 右值中甚至可以有左值 ```python -# i 是左值,Array(Int) 和 [1, 2, 3] 是右值 -i: Array(Int) = [1, 2, 3] +# i 是左值,List(Int) 和 [1, 2, 3] 是右值 +i: List(Int) = [1, 2, 3] # `[1, 2, 3].iter().map i -> i + 1`是右值,但是`->`左邊的i是左值 a = [1, 2, 3].iter().map i -> i + 1 # {x = 1; y = 2} 是右值,但 `x`, `y` 是左值 diff --git a/doc/zh_TW/syntax/01_literal.md b/doc/zh_TW/syntax/01_literal.md index 3764479b2..d3a194825 100644 --- a/doc/zh_TW/syntax/01_literal.md +++ b/doc/zh_TW/syntax/01_literal.md @@ -72,7 +72,7 @@ assert 1e-10 == 0.0000000001 這些文字中的每一個都有自己的文檔分別描述它們,因此請參閱該文檔以獲取詳細信息 -### [數組字面量](./10_array.md) +### [數組字面量](./10_list.md) ```python [], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ... @@ -102,7 +102,7 @@ assert 1e-10 == 0.0000000001 {}, {1}, {1, 2, 3}, {"1", "2", "1"}, {1, "1", True, [1]} ... ``` -與 `Array` 字面量不同的是,`Set` 中刪除了重復元素 +與 `List` 字面量不同的是,`Set` 中刪除了重復元素 ```python assert {1, 2, 1} == {1, 2} diff --git a/doc/zh_TW/syntax/09_builtin_procs.md b/doc/zh_TW/syntax/09_builtin_procs.md index a992d7676..47cdd76d7 100644 --- a/doc/zh_TW/syntax/09_builtin_procs.md +++ b/doc/zh_TW/syntax/09_builtin_procs.md @@ -12,5 +12,5 @@ ```

- 上一頁 | 下一頁 + 上一頁 | 下一頁

diff --git a/doc/zh_TW/syntax/10_array.md b/doc/zh_TW/syntax/10_list.md similarity index 81% rename from doc/zh_TW/syntax/10_array.md rename to doc/zh_TW/syntax/10_list.md index a5d80c30b..2cfa70070 100644 --- a/doc/zh_TW/syntax/10_array.md +++ b/doc/zh_TW/syntax/10_list.md @@ -1,6 +1,6 @@ # 數組 -[![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) 數組是最基本的__collection(聚合)__ 集合是一個可以在其中包含多個對象的對象 diff --git a/doc/zh_TW/syntax/11_dict.md b/doc/zh_TW/syntax/11_dict.md index 8b0e96d4d..80307b493 100644 --- a/doc/zh_TW/syntax/11_dict.md +++ b/doc/zh_TW/syntax/11_dict.md @@ -66,5 +66,5 @@ valid2: {Int: Int or Str} = {1: "a", 2: 2} ```

- 上一頁 | 下一頁 + 上一頁 | 下一頁

diff --git a/doc/zh_TW/syntax/17_iterator.md b/doc/zh_TW/syntax/17_iterator.md index 79def0547..ee9233ca3 100644 --- a/doc/zh_TW/syntax/17_iterator.md +++ b/doc/zh_TW/syntax/17_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() # <數組迭代器對象> log (1..3).iter() # ``` -`ArrayIterator` 和 `RangeIterator` 都是實現 `Iterator` 的類,它們的存在只是為了提供 `Array` 和 `Range` 迭代函數 +`ListIterator` 和 `RangeIterator` 都是實現 `Iterator` 的類,它們的存在只是為了提供 `List` 和 `Range` 迭代函數 這種設計模式稱為伴生類 [1](#1) -而"IteratorImpl"補丁是迭代功能的核心。`Iterator` 只需要一個`.next` 方法,`IteratorImpl` 確實提供了幾十種方法。`ArrayIterator`和`RangeIterator`只需實現`.next`方法就可以使用`IteratorImpl`的實現方法。為了方便起見,標準庫實現了許多迭代器 +而"IteratorImpl"補丁是迭代功能的核心。`Iterator` 只需要一個`.next` 方法,`IteratorImpl` 確實提供了幾十種方法。`ListIterator`和`RangeIterator`只需實現`.next`方法就可以使用`IteratorImpl`的實現方法。為了方便起見,標準庫實現了許多迭代器 ```mermaid classDiagram - class Array~T~ { + class List~T~ { ... - iter() ArrayIterator~T~ + iter() ListIterator~T~ } class Range~T~ { ... @@ -59,10 +59,10 @@ classDiagram <> iter() Iterator~T~ } - Iterable~T~ <|.. Array~T~: Impl + Iterable~T~ <|.. List~T~: Impl Iterable~T~ <|.. Range~T~: Impl - class ArrayIterator~T~ { - array: Array~T~ + class ListIterator~T~ { + array: List~T~ next() T } class RangeIterator~T~ { @@ -73,10 +73,10 @@ classDiagram <> next() T } - Iterator~T~ <|.. ArrayIterator~T~: Impl + Iterator~T~ <|.. ListIterator~T~: Impl Iterator~T~ <|.. RangeIterator~T~: Impl - Array <-- ArrayIterator + List <-- ListIterator Range <-- RangeIterator ``` diff --git a/doc/zh_TW/syntax/20_visibility.md b/doc/zh_TW/syntax/20_visibility.md index 1c8b5d09c..84925a78a 100644 --- a/doc/zh_TW/syntax/20_visibility.md +++ b/doc/zh_TW/syntax/20_visibility.md @@ -189,5 +189,5 @@ _ = foo.record.a.z # OK ```

- 上一頁 | 下一頁 -

\ No newline at end of file + 上一頁 | 下一頁 +

diff --git a/doc/zh_TW/syntax/21_naming_rule.md b/doc/zh_TW/syntax/21_naming_rule.md index 5f58fabdd..c9fdab4f7 100644 --- a/doc/zh_TW/syntax/21_naming_rule.md +++ b/doc/zh_TW/syntax/21_naming_rule.md @@ -1,6 +1,6 @@ # 命名規定 -[![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/21_naming_rule.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/21_naming_rule.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) +[![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/22_naming_rule.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/22_naming_rule.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) 如果要將變量用作常量表達式,請確保它以大寫字母開頭。兩個或多個字母可能是小寫的 @@ -49,4 +49,4 @@ bar! = pyimport("foo").'bar'

上一頁 | 下一頁 -

\ No newline at end of file +

diff --git a/doc/zh_TW/syntax/22_lambda.md b/doc/zh_TW/syntax/22_lambda.md index d2264206c..a637b3940 100644 --- a/doc/zh_TW/syntax/22_lambda.md +++ b/doc/zh_TW/syntax/22_lambda.md @@ -93,5 +93,5 @@ id = |T| x: T -> x ```

- 上一頁 | 下一頁 -

\ No newline at end of file + 上一頁 | 下一頁 +

diff --git a/doc/zh_TW/syntax/27_pattern_matching.md b/doc/zh_TW/syntax/27_pattern_matching.md index b46942fc4..7b8728bd3 100644 --- a/doc/zh_TW/syntax/27_pattern_matching.md +++ b/doc/zh_TW/syntax/27_pattern_matching.md @@ -25,7 +25,7 @@ fn: Int -> Int = x -> x + 1 # 高階類型 a: [Int; 4] = [0, 1, 2, 3] # or -a: Array Int, 4 = [0, 1, 2, 3] +a: List Int, 4 = [0, 1, 2, 3] ``` ### 文字字面量 @@ -68,8 +68,8 @@ name = match num: ```python,checker_ignore # 這兩個是一樣的 -Array(T, N: {N | N >= 3}) -Array(T, N | N >= 3) +List(T, N: {N | N >= 3}) +List(T, N | N >= 3) f M, N | M >= 0, N >= 1 = ... f(1, 0) # 類型錯誤: N(第二個參數)必須為 1 或更多 diff --git a/doc/zh_TW/syntax/28_comprehension.md b/doc/zh_TW/syntax/28_comprehension.md index 2c33c7a37..9935a7132 100644 --- a/doc/zh_TW/syntax/28_comprehension.md +++ b/doc/zh_TW/syntax/28_comprehension.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/28_comprehension.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/28_comprehension.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) -Array和`[expr | (name <- iterable)+ (predicate)*]`, +List和`[expr | (name <- iterable)+ (predicate)*]`, set和`{expr | (name <- iterable)+ (predicate)*}`, 你可以創建一個字典`{key: value | (name <- iterable)+ (predicate)*}`. diff --git a/doc/zh_TW/syntax/30_decorator.md b/doc/zh_TW/syntax/30_decorator.md index f9343924e..1674043e6 100644 --- a/doc/zh_TW/syntax/30_decorator.md +++ b/doc/zh_TW/syntax/30_decorator.md @@ -118,5 +118,5 @@ assert Y in U. attaches 表示這是一個測試子例程。測試子程序使用`erg test`命令運行

- 上一頁 | 下一頁 + 上一頁 | 下一頁

diff --git a/doc/zh_TW/syntax/31_error_handling.md b/doc/zh_TW/syntax/31_error_handling.md index dcfa22214..867adc524 100644 --- a/doc/zh_TW/syntax/31_error_handling.md +++ b/doc/zh_TW/syntax/31_error_handling.md @@ -1,6 +1,6 @@ # 錯誤處理系統 -[![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/31_error_handling.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/31_error_handling.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) +[![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/32_error_handling.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/32_error_handling.md&commit_hash=e959b3e54bfa8cee4929743b0193a129e7525c61) 主要使用Result類型 在Erg中,如果您丟棄Error類型的對象(頂層不支持),則會發生錯誤 @@ -108,4 +108,4 @@ panic "something went wrong!"

上一頁 | 下一頁 -

\ No newline at end of file +

diff --git a/doc/zh_TW/syntax/32_pipeline.md b/doc/zh_TW/syntax/32_pipeline.md index 5e64e452c..b7dec1cdc 100644 --- a/doc/zh_TW/syntax/32_pipeline.md +++ b/doc/zh_TW/syntax/32_pipeline.md @@ -19,16 +19,16 @@ log rand # 0.2597... 1+1*2 |>.times do log("a", end := "") # aaa -evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect Array +evens = 1..100 |>.iter() |>.filter i -> i % 2 == 0 |>.collect List # 在沒有管道操作符的情況下實現, -_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(Array) +_evens = (1..100).iter().filter(i -> i % 2 == 0).collect(List) # or __evens = 1..100 \ .iter() \ .filter i -> i % 2 == 0 \ - .collect Array + .collect List ```

- 上一頁 | 下一頁 + 上一頁 | 下一頁

diff --git a/doc/zh_TW/syntax/SUMMARY.md b/doc/zh_TW/syntax/SUMMARY.md index 8a412e090..fb422918c 100644 --- a/doc/zh_TW/syntax/SUMMARY.md +++ b/doc/zh_TW/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) @@ -65,7 +65,7 @@ - [可變性](./18_mutability.md) - [所有權](./19_ownership.md) - [可見性](./20_visibility.md) -- [命名規定](./21_naming_rule.md) +- [命名規定](./22_naming_rule.md) - [Lambda](./22_lambda.md) - [子程序](./23_subroutine.md) - [閉包](./24_closure.md) @@ -75,7 +75,7 @@ - [推導式](./28_comprehension.md) - [擴展語法](./29_spread_syntax.md) - [裝飾器](./30_decorator.md) -- [錯誤處理系統](./31_error_handling.md) +- [錯誤處理系統](./32_error_handling.md) - [管道運算符](./32_pipeline.md) - [與 Python 集成](./33_integration_with_Python.md) - [包系統](./34_package_system.md) diff --git a/doc/zh_TW/syntax/indexes.md b/doc/zh_TW/syntax/indexes.md index 551658cf0..65dc111b9 100644 --- a/doc/zh_TW/syntax/indexes.md +++ b/doc/zh_TW/syntax/indexes.md @@ -54,7 +54,7 @@ * >> * >= * @ → [decorator](./29_decorator.md) -* [] → [Array](./10_array.md) +* [] → [List](./10_list.md) * \ → [Indention](./00_basic.md) * \ → [Str](./01_literal.md) * ^ @@ -85,7 +85,7 @@ * [anonymous function](./21_lambda.md) * [Anonymous polycorrelation coefficient](./21_lambda.md) * anonymous type → [Type System](./type/01_type_system.md) -* [Array](./10_array.md) +* [List](./10_list.md) * [assert] * [Attach](./29_decorator.md) * [attribute](type/09_attributive.md) diff --git a/doc/zh_TW/syntax/type/01_type_system.md b/doc/zh_TW/syntax/type/01_type_system.md index b4d81548b..49b3b0ba6 100644 --- a/doc/zh_TW/syntax/type/01_type_system.md +++ b/doc/zh_TW/syntax/type/01_type_system.md @@ -47,14 +47,14 @@ Erg 的類型系統包含結構子類型 (SST)。該系統類型化的類型稱 整個名義類型的類型(`NominalType`)和整個結構類型的類型(`StructuralType`)是整個類型(`Type`)的類型的子類型 -Erg 可以將參數(類型參數)傳遞給類型定義。帶有類型參數的 `Option`、`Array` 等稱為多項式類型。這些本身不是類型,但它們通過應用參數成為類型。諸如 `Int`、`Str` 等沒有參數的類型稱為簡單類型(標量類型) +Erg 可以將參數(類型參數)傳遞給類型定義。帶有類型參數的 `Option`、`List` 等稱為多項式類型。這些本身不是類型,但它們通過應用參數成為類型。諸如 `Int`、`Str` 等沒有參數的類型稱為簡單類型(標量類型) 一個類型可以看成一個集合,并且存在包含關系。例如,"Num"包含"Add"、"Sub"等,"Int"包含"Nat" 所有類的上類是`Object == Class {:}`,所有類型的下類是`Never == Class {}`。這在下面描述 ## 類型 -像 `Array T` 這樣的類型可以看作是 `Type -> Type` 類型的函數,它以 `T` 類型為參數并返回 `Array T` 類型(在類型論中也稱為 Kind)。像 `Array T` 這樣的類型專門稱為多態類型,而 `Array` 本身稱為一元 Kind +像 `List T` 這樣的類型可以看作是 `Type -> Type` 類型的函數,它以 `T` 類型為參數并返回 `List T` 類型(在類型論中也稱為 Kind)。像 `List T` 這樣的類型專門稱為多態類型,而 `List` 本身稱為一元 Kind 已知參數和返回類型的函數的類型表示為`(T, U) -> V`。如果要指定同一類型的整個雙參數函數,可以使用 `|T| (T, T) -> T`,如果要指定整個 N 參數函數,可以使用 `Func N`。但是,`Func N` 類型沒有關于參數數量或其類型的信息,因此所有返回值在調用時都是`Obj` 類型 @@ -62,7 +62,7 @@ Erg 可以將參數(類型參數)傳遞給類型定義。帶有類型參數的 ` `Method` 類型是一個函數/過程,其第一個參數是它所屬的對象 `self`(通過引用)。對于依賴類型,也可以在應用方法后指定自己的類型。這是 `T!(!N)` 類型和 `T!(N ~> N-1)。() => Int` 等等 -Erg 的數組(Array)就是 Python 所說的列表。`[詮釋; 3]`是一個數組類,包含三個`Int`類型的對象 +Erg 的數組(List)就是 Python 所說的列表。`[詮釋; 3]`是一個數組類,包含三個`Int`類型的對象 > __Note__: `(Type; N)` 既是類型又是值,所以可以這樣使用 > @@ -115,7 +115,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/zh_TW/syntax/type/02_basic.md b/doc/zh_TW/syntax/type/02_basic.md index 366cee309..11eb077d1 100644 --- a/doc/zh_TW/syntax/type/02_basic.md +++ b/doc/zh_TW/syntax/type/02_basic.md @@ -24,11 +24,11 @@ f([1, "a"]: [Int or Str]) ```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 # 大寫變量的值必須是常量表達式 @@ -133,7 +133,7 @@ C:: Id = Int Point3D = {x = Int; y = Int; z = Int} IorS = Int or Str -Vector = Array Int +Vector = List Int ``` 此外,當顯示錯誤時,如果定義了復合類型(在上面的示例中,右側類型不是第一個類型),編譯器將為它們使用別名 @@ -146,8 +146,8 @@ Vector = Array Int Id = Int UserId = Int # 類型警告: 重復別名: Id 和 UserId -Ids = Array Id -Ints = Array Int # 類型警告: 重復別名: Isd 和 Ints +Ids = List Id +Ints = List Int # 類型警告: 重復別名: Isd 和 Ints IorS = Int or Str IorSorB = IorS or Bool diff --git a/doc/zh_TW/syntax/type/03_trait.md b/doc/zh_TW/syntax/type/03_trait.md index 8421534c7..60bfb8811 100644 --- a/doc/zh_TW/syntax/type/03_trait.md +++ b/doc/zh_TW/syntax/type/03_trait.md @@ -44,7 +44,7 @@ Trait 也是一種類型,因此可以用于普通類型規范 ```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包含 @@ -117,11 +117,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"]. ``` ## OverrideTrait @@ -181,7 +181,7 @@ print! P|<: Mul(Int)|.Output # ## 附錄: 與 Rust Trait的區別 -Erg 的Trait忠實于 [Sch?rli 等人] (https://www.ptidej.net/courses/ift6251/fall06/presentations/061122/061122.doc.pdf) 提出的Trait +Erg 的Trait忠實于 [Sch?rli 等人] () 提出的Trait 為了允許代數運算,Trait被設計為不能有方法實現目錄,但可以在必要時進行修補

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]