diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 76be74ff0..dff033d9c 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "11"; public const string Build = "0"; - public const string Revision = "3666"; + public const string Revision = "3669"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 8d911771f..2dca8433c 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=0 -%REVISION%=3666 %MINOR%=11 +%REVISION%=3669 +%COREVERSION%=0 %MAJOR%=3 diff --git a/InstallerSamples/!MainFeatures/01_First/Amp.pas b/InstallerSamples/!MainFeatures/01_First/Amp.pas index 41d02e2e7..718ab4e25 100644 --- a/InstallerSamples/!MainFeatures/01_First/Amp.pas +++ b/InstallerSamples/!MainFeatures/01_First/Amp.pas @@ -1,10 +1,8 @@ // Пример иллюстрирует использование знака "&" для снятия атрибута ключевого слова -var - &begin,&end: integer; - i: integer; - begin + var &begin,&end: integer; + &begin := 1; &end := 2; var t: System.Type := &begin.GetType; // в System.Type использовать & не надо diff --git a/InstallerSamples/!MainFeatures/01_First/Amp2.pas b/InstallerSamples/!MainFeatures/01_First/Amp2.pas index 5c6e50bba..97162e8ca 100644 --- a/InstallerSamples/!MainFeatures/01_First/Amp2.pas +++ b/InstallerSamples/!MainFeatures/01_First/Amp2.pas @@ -1,7 +1,7 @@ // Пример иллюстрирует использование знака "&" для явного указания шаблонного типа подпрограммы function GetDefault: T := -default(T); + default(T); type GenericType = class @@ -10,8 +10,7 @@ type end; begin - -// var o := GetDefault; //Ошибка: Встречено ';', а ожидалось выражение + // var o := GetDefault; //Ошибка: Встречено ';', а ожидалось выражение // компилятор не отличает знак сравнения < от открытия угловой скобки // и поэтому видит эту строчку как "(GetDefault < byte) > ;" // ";" там оказывается неожиданно, потому что компилятор ожидал ещё какое то выражение для сравнения diff --git a/InstallerSamples/!MainFeatures/01_First/AssignExt.pas b/InstallerSamples/!MainFeatures/01_First/AssignExt.pas index 3ba218714..0c2206bc7 100644 --- a/InstallerSamples/!MainFeatures/01_First/AssignExt.pas +++ b/InstallerSamples/!MainFeatures/01_First/AssignExt.pas @@ -1,17 +1,14 @@ -// Присваивания += -= *= /= -var - i: integer; - r: real; +// Присваивания += -= *= /= begin - i := 1; + var i: integer := 1; writeln('i := 1; i = ',i); i += 2; // Увеличение на 2 writeln('i += 2; i = ',i); i *= 3; // Умножение на 3 writeln('i *= 3; i = ',i); writeln; - r := 6; + var r: real := 6; writeln('r := 6; r = ',r); r /= 2; writeln('r /= 2; r = ',r); diff --git a/InstallerSamples/!MainFeatures/01_First/AutoVars.pas b/InstallerSamples/!MainFeatures/01_First/AutoVars.pas index 25797a7bb..8a2b8b854 100644 --- a/InstallerSamples/!MainFeatures/01_First/AutoVars.pas +++ b/InstallerSamples/!MainFeatures/01_First/AutoVars.pas @@ -1,10 +1,10 @@ -// Автоопределение типа переменной +// Автоопределение типа переменной // Описание переменной в заголовке цикла for begin var x := 2; for var i:=1 to 10 do begin - write(x,' '); + Print(x); x += 2; end; end. \ No newline at end of file diff --git a/InstallerSamples/!MainFeatures/01_First/BlockVar.pas b/InstallerSamples/!MainFeatures/01_First/BlockVar.pas index d1257db6c..c35a376e2 100644 --- a/InstallerSamples/!MainFeatures/01_First/BlockVar.pas +++ b/InstallerSamples/!MainFeatures/01_First/BlockVar.pas @@ -1,11 +1,11 @@ -// Перемена местами значений двух переменных с использованием третьей -var x,y: real; +// Перемена местами значений двух переменных с использованием третьей begin - write('Введите x,y: '); - readln(x,y); - var v: real := x; // вспомогательная переменная + var (x,y) := ReadReal2('Введите x,y:'); + + var v := x; // вспомогательная переменная x := y; y := v; - writeln('Новые значения x,y: ',x,' ',y); + + Println($'Новые значения x,y: {x} {y}'); end. \ No newline at end of file diff --git a/InstallerSamples/!MainFeatures/01_First/Foreach.pas b/InstallerSamples/!MainFeatures/01_First/Foreach.pas index fb505aca3..aafbd39f4 100644 --- a/InstallerSamples/!MainFeatures/01_First/Foreach.pas +++ b/InstallerSamples/!MainFeatures/01_First/Foreach.pas @@ -1,22 +1,19 @@ // Пример иллюстрирует возможности оператора foreach -var - a: array [1..5] of integer := (1,3,5,7,9); - s: set of integer; - l: List; begin + var a: array of integer := [1,3,5,7,9]; Write('foreach по обычному массиву: ':35); foreach x: integer in a do Print(x); Println; - s := [2..5,10..14]; + var s: set of integer := [2..5,10..14]; Write('foreach по множеству: ':35); foreach var x in s do Print(x); Println; - l := new List; + var l := new List; l.Add(7); l.Add(2); l.Add(5); Write('foreach по динамическому массиву: ':35); foreach var x in l do diff --git a/InstallerSamples/!MainFeatures/01_First/Print.pas b/InstallerSamples/!MainFeatures/01_First/Print.pas index 3d61f6519..badb26284 100644 --- a/InstallerSamples/!MainFeatures/01_First/Print.pas +++ b/InstallerSamples/!MainFeatures/01_First/Print.pas @@ -1,4 +1,4 @@ -/// Вывод с помощью Print +/// Вывод с помощью Print - данные разделяются пробелами begin Print(1,2,3) end. \ No newline at end of file diff --git a/InstallerSamples/!MainFeatures/01_First/RealExtNums.pas b/InstallerSamples/!MainFeatures/01_First/RealExtNums.pas index 5e099f699..416a26566 100644 --- a/InstallerSamples/!MainFeatures/01_First/RealExtNums.pas +++ b/InstallerSamples/!MainFeatures/01_First/RealExtNums.pas @@ -1,5 +1,5 @@ -// При работе с вещественными числами невозможно получить ошибку выполнения +// При работе с вещественными числами невозможно получить ошибку выполнения begin - writeln(1/0); - writeln(sqrt(-1)); + Println(1/0); // Infinity + Println(Sqrt(-1)); // Not A Number end. \ No newline at end of file diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 0c0a0ebc2..2808df85c 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.11.0.3666 +3.11.0.3669 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 51fbc55cb..01b27e480 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.11.0.3666' +!define VERSION '3.11.0.3669' diff --git a/TestSuite/CompilationSamples/SPythonHidden.pas b/TestSuite/CompilationSamples/SPythonHidden.pas index c1a5cafa4..cde9322e1 100644 --- a/TestSuite/CompilationSamples/SPythonHidden.pas +++ b/TestSuite/CompilationSamples/SPythonHidden.pas @@ -3,7 +3,7 @@ unit SPythonHidden; interface -// uses PABCSystem; +uses SPythonSystem; function !Floor(x : real) : integer; @@ -14,8 +14,36 @@ function !FloorMod(x: real; y: real): real; type !UnknownType = class end; +// TODO: Перенести в SPythonSystemPys следующие методы +function list(sq: sequence of T): SPythonSystem.list; + +function list(d : dict) : SPythonSystem.list; + +function &set(sq: sequence of T): &set; + +function &set(): empty_set; + +function dict(params pairs: array of (TKey, TVal)): dict; + +function dict(seqOfPairs: IEnumerable>) : dict; + implementation +function list(sq: sequence of T): SPythonSystem.list := new SPythonSystem.list(sq); + +function list(d : dict) : SPythonSystem.list := new SPythonSystem.list(d.keys()); + +function &set(sq: sequence of T): &set; +begin + Result := new &set(sq); +end; + +function &set(): empty_set := new empty_set; + +function dict(params pairs: array of (TKey, TVal)): dict := new dict(pairs); + +function dict(seqOfPairs: sequence of (TKey, TVal)): dict := new dict(seqOfPairs); + function !Floor(x : real) : integer := PABCSystem.Floor(x); function !FloorDiv(x: real; y: real): integer := PABCSystem.Floor(x / y); diff --git a/TestSuite/CompilationSamples/SPythonSystem.pas b/TestSuite/CompilationSamples/SPythonSystem.pas index c47ee1f55..6c0a15b2b 100644 --- a/TestSuite/CompilationSamples/SPythonSystem.pas +++ b/TestSuite/CompilationSamples/SPythonSystem.pas @@ -17,6 +17,7 @@ function input(): string; function input(s: string): string; +///- type kwargs_gen = class public !kwargs: Dictionary := new Dictionary(); @@ -50,10 +51,6 @@ function filter(cond: T -> boolean; s: sequence of T): sequence of T; function sorted(s: sequence of T; reverse: boolean := false): sequence of T; function sorted(s: sequence of T; key: T -> T1; reverse: boolean := false): sequence of T; -function __NewSetCreatorInternal(params a: array of T): NewSet; - -procedure clear(var st: set of T); - function int(val: string): integer; function int(val: real): integer; @@ -102,18 +99,395 @@ function abs(x: real): real; // function floor(x: real): real; +type list = class(IEnumerable) + private + wrappee : PABCSystem.List; + + constructor Create(l : PABCSystem.List) := wrappee := l; + + function GetItem(ind : integer) : T := wrappee[ind]; + + procedure SetItem(ind : integer; newItem : T) := wrappee[ind] := newItem; + + public + + static function operator implicit(l : PABCSystem.List) : list := new list(l); + + constructor Create() := wrappee := new PABCSystem.List(); + + constructor Create(capacity : integer) := wrappee := new PABCSystem.List(capacity); + + constructor Create(collection : sequence of T) := wrappee := new PABCSystem.List(collection); + + property ByIndex[ind : integer] : T read GetItem write SetItem; default; + + ///-- + property !count : integer read wrappee.Count; + + procedure append(item : T) := wrappee.Add(item); + + procedure extend(seq : sequence of T) := wrappee.AddRange(seq); + + procedure clear() := wrappee.Clear(); + + procedure insert(index : integer; item : T) := wrappee.Insert(index, item); + + procedure remove(item : T); + begin + if not wrappee.Remove(item) then + raise new System.ArgumentException($'ValueError: {item} is not in list'); + end; + + function pop() : T; + begin + var lastIndex := wrappee.Count - 1; + Result := wrappee[lastIndex]; + wrappee.RemoveAt(lastIndex); + end; + + function pop(index : integer) : T; + begin + Result := wrappee[index]; + wrappee.RemoveAt(index); + end; + + function index(item : T) : integer := index(item, 0, wrappee.Count); + + function index(item : T; start : integer) : integer := index(item, start, wrappee.Count); + + function index(item : T; start : integer; &end : integer) : integer; + begin + Result := wrappee.IndexOf(item, start, &end - start); + if Result = -1 then + raise new System.ArgumentException($'ValueError: {item} is not in list'); + end; + + function count(item : T) : integer; + begin + var comparer := System.Collections.Generic.EqualityComparer&.Default; + + Result := 0; + for var i := 0 to wrappee.Count - 1 do + begin + if comparer.Equals(wrappee[i], item) then + Result += 1; + end; + end; + + procedure sort() := wrappee.Sort(); + + procedure sort(reverse : boolean) := wrappee.OrderByDescending(x -> x); + + procedure sort(key : T -> TKey) := wrappee.OrderBy(key); + + procedure sort(key : T -> TKey; reverse : boolean) := wrappee.OrderByDescending(key); + + procedure reverse() := wrappee.Reverse(); + + function copy() : list := new list(wrappee.ToList()); + + function GetEnumerator() : IEnumerator := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); + end; + +type &set = record(IEnumerable) + private + wrappee : PABCSystem.HashSet; + + constructor Create(h : PABCSystem.HashSet) := wrappee := h; + + public + + constructor Create() := wrappee := new PABCSystem.HashSet(); + + constructor Create(collection : sequence of T) := wrappee := new PABCSystem.HashSet(collection); + + constructor Create(collection : sequence of T; comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.HashSet(collection, comparer); + + constructor Create(comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.HashSet(comparer); + + ///-- + property !count : integer read wrappee.Count; + + procedure add(elem : T) := wrappee.Add(elem); + + procedure remove(elem : T); + begin + if not wrappee.Remove(elem) then + raise new System.Collections.Generic.KeyNotFoundException('KeyError: ' + elem.ToString()); + end; + + procedure discard(elem : T) := wrappee.Remove(elem); + + function pop() : T; + begin + if wrappee.Count = 0 then + raise new System.Collections.Generic.KeyNotFoundException('KeyError: ''pop from an empty set'''); + + Result := wrappee.First(); + wrappee.Remove(Result); + end; + + procedure clear() := wrappee.Clear(); + + function copy() : &set := new &set(wrappee.ToHashSet()); + + static function operator in(elem: T; Self: &set): boolean; + begin + Result := Self.wrappee.Contains(elem); + end; + + private + function setOperation1(op : (HashSet, sequence of T) -> (); params others : array of sequence of T) : &set; + begin + Result.wrappee := wrappee.ToHashSet(); + foreach var seq in others do + op(Result.wrappee, seq); + end; + + procedure setOperation2(op : (HashSet, sequence of T) -> (); params others : array of sequence of T); + begin + foreach var seq in others do + op(wrappee, seq); + end; + + public + function intersection(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.IntersectWith(h2), others); + + function union(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.UnionWith(h2), others); + + function difference(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.ExceptWith(h2), others); + + function symmetric_difference(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.SymmetricExceptWith(h2), others); + + procedure update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.UnionWith(h2), others); + + procedure update(other : sequence of T) := wrappee.UnionWith(other); + + procedure intersection_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.IntersectWith(h2), others); + + procedure intersection_update(other : sequence of T) := wrappee.IntersectWith(other); + + procedure difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.ExceptWith(h2), others); + + procedure difference_update(other : sequence of T) := wrappee.ExceptWith(other); + + procedure symmetric_difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.SymmetricExceptWith(h2), others); + + procedure symmetric_difference_update(other : sequence of T) := wrappee.SymmetricExceptWith(other); + + function isdisjoint(other : sequence of T) : boolean; + + function issubset(other : sequence of T) : boolean := wrappee.IsSubsetOf(other); + + function issuperset(other : sequence of T) : boolean := wrappee.IsSupersetOf(other); + + static function operator=(s1 : &set; s2 : &set) : boolean := s1.wrappee.SetEquals(s2.wrappee); + + static function operator<>(s1 : &set; s2 : &set) : boolean := not (s1 = s2); + + static function operator<=(s1 : &set; s2 : &set) : boolean := s1.issubset(s2); + + static function operator<(s1 : &set; s2 : &set) : boolean := (s1 <= s2) and (s1 <> s2); + + static function operator>=(s1 : &set; s2 : &set) : boolean := s1.issuperset(s2); + + static function operator>(s1 : &set; s2 : &set) : boolean := (s1 >= s2) and (s1 <> s2); + + static function operator or(s1 : &set; s2 : &set) : &set := s1.union(s2); + + ///- + function !orEqual(other : &set) : &set; + begin + update(other); + Result := Self; + end; + + static function operator and(s1 : &set; s2 : &set) : &set := s1.intersection(s2); + + ///- + function !andEqual(other : &set) : &set; + begin + intersection_update(other); + Result := Self; + end; + + static function operator-(s1 : &set; s2 : &set) : &set := s1.difference(s2); + + static function operator -=(var s1 : &set; s2 : &set) : &set; + begin + s1.difference_update(s2); + end; + + static function operator xor(s1 : &set; s2 : &set) : &set := s1.symmetric_difference(s2); + + ///- + function !xorEqual(other : &set) : &set; + begin + symmetric_difference_update(other); + Result := Self; + end; + +// static function operator:=(var s1: &set; s2: &set): &set; +// begin +// s1.wrappee := s2.wrappee.ToHashSet(); +// end; + + static function operator implicit(s : HashSet) : &set := new &set(s); + + function GetEnumerator() : IEnumerator := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); +end; + +type dict = class(IEnumerable>) + private + wrappee : PABCSystem.Dictionary; + + constructor Create(d : PABCSystem.Dictionary) := wrappee := d; + + function GetValue(key : K) : V := wrappee[key]; + + procedure SetValue(key : K; val : V) := wrappee[key] := val; + + public + + constructor Create() := wrappee := new PABCSystem.Dictionary(); + + constructor Create(capacity : integer) := wrappee := new PABCSystem.Dictionary(capacity); + + constructor Create(comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.Dictionary(comparer); + + constructor Create(capacity : integer; comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.Dictionary(capacity, comparer); + + constructor Create(params pairs: array of (K, V)); + begin + wrappee := new PABCSystem.Dictionary(); + + for var i := 0 to pairs.Length - 1 do + wrappee[pairs[i].Item1] := pairs[i].Item2; + end; + + constructor Create(seqOfPairs : sequence of (K, V)); + begin + wrappee := new PABCSystem.Dictionary(); + + foreach var p in seqOfPairs do + wrappee[p.Item1] := p.Item2; + end; + + ///-- + property !count : integer read wrappee.Count; + + property ByKey[key : K] : V read GetValue write SetValue; default; + + static function operator in(key: K; Self: dict): boolean; + begin + Result := Self.wrappee.ContainsKey(key); + end; + + procedure clear() := wrappee.Clear(); + + function copy() : dict := new dict(new Dictionary(wrappee)); + + static function fromkeys(sq : sequence of K; val : V := default(V)) : dict; + begin + Result := new dict(); + + foreach var key in sq do + Result[key] := val; + end; + + function get(key : K; &default : V := default(V)) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + Result := val + else + Result := &default; + end; + + function items() : sequence of KeyValuePair := wrappee; + + function keys() := wrappee.Keys; + + function pop(key : K) : V; + begin + Result := wrappee[key]; + wrappee.Remove(key); + end; + + function pop(key : K; &default : V) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + begin + Result := val; + wrappee.Remove(key); + end + else + Result := &default; + end; + + function popitem() : KeyValuePair; + begin + Result := wrappee.Last(); + wrappee.Remove(Result.Key); + end; + + function setdefault(key : K; &default : V := default(V)) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + Result := val + else + begin + wrappee[key] := &default; + Result := &default; + end; + end; + + procedure update(params pairs: array of (K, V)); + begin + for var i := 0 to pairs.Length - 1 do + wrappee[pairs[i].Item1] := pairs[i].Item2; + end; + + procedure update(seqOfPairs : sequence of (K, V)); + begin + foreach var p in seqOfPairs do + wrappee[p.Item1] := p.Item2; + end; + + function values() := wrappee.Values; + + static function operator or(d1 : dict; d2 : dict) : dict; + begin + Result := new dict(d1.wrappee); + + foreach var p in d2.wrappee do + Result[p.Key] := p.Value; + end; + + static function operator implicit(d : PABCSystem.Dictionary) : dict := new dict(d); + + function GetEnumerator() : IEnumerator> := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); +end; + //Standard functions with Lists -function len(lst: PABCSystem.List): integer; -function len(st: set of T): integer; -function len(dct: PABCSystem.Dictionary): integer; +function len(lst: list): integer; +function len(st: &set): integer; +function len(dct: dict): integer; function len(arr: array of T): integer; function len(s: string): integer; -function &set(sq: sequence of T): set of T; -function &list(sq: sequence of T): PABCSystem.List; +// function &set(sq: sequence of T): &set; -function sorted(lst: PABCSystem.List): PABCSystem.List; +function sorted(lst: list): list; function sum(lst: sequence of integer): integer; @@ -162,14 +536,8 @@ function CreateTuple( // TUPLES END -function Dict(params pairs: array of (TKey, TVal)): Dictionary; - type biginteger = PABCSystem.BigInteger; - !list = PABCSystem.List; - !dict = PABCSystem.Dictionary; - dct = PABCSystem.Dictionary; - !set = set of T; tuple2 = System.Tuple; tuple3 = System.Tuple; tuple4 = System.Tuple; @@ -178,30 +546,30 @@ type tuple7 = System.Tuple; empty_list = class - class function operator implicit(x: empty_list): !list; + class function operator implicit(x: empty_list): list; begin - Result := new !list(); + Result := new list(); end; end; empty_set = class - class function operator implicit(x: empty_set): !set; + class function operator implicit(x: empty_set): &set; begin - Result := new !set; + Result := new &set(); end; end; empty_dict = class - class function operator implicit(x: empty_dict): !dict; + class function operator implicit(x: empty_dict): dict; begin - Result := new !dict(); + Result := new dict(); end; end; function !empty_list(): empty_list; function !empty_dict(): empty_dict; -function &set(): empty_set; + implementation @@ -246,8 +614,6 @@ begin Result := TypeName(obj) .Replace('<', '[') .Replace('>', ']') - .Replace('List', 'list') - .Replace('Dictionary', 'dict') .Replace('empty_list', 'list[anytype]') .Replace('empty_set', 'set[anytype]') .Replace('empty_dict', 'dict[anytype]') @@ -289,17 +655,17 @@ function abs(x: integer): integer := if x >= 0 then x else -x; function abs(x: real): real := PABCSystem.Abs(x); -function len(lst: PABCSystem.List): integer := lst.Count(); -function len(st: set of T): integer := st.Count(); -function len(dct: PABCSystem.Dictionary): integer := dct.Count(); -function len(arr: array of T): integer := arr.Count(); +function len(lst: list): integer := lst.!count; +function len(st: &set): integer := st.!count; +function len(dct: dict): integer := dct.!count; +function len(arr: array of T): integer := arr.Length; function len(s: string): integer := s.Length; -function sorted(lst: PABCSystem.List): PABCSystem.List; +function sorted(lst: list): list; begin - var new_list := new PABCSystem.List(lst); - new_list.sort(); - Result := new_list; + var newList := lst.copy(); + newList.sort(); + Result := newList; end; function sum(lst: sequence of integer): integer := lst.sum(); @@ -360,49 +726,32 @@ begin Result := x; end; -function !count(Self: PABCSystem.List; val: T): integer; extensionmethod; +function &set.isdisjoint(other : sequence of T) : boolean; begin - Result := 0; - for var i := 0 to Self.Count - 1 do - if val = Self[i] then - Result += 1; -end; - -function pop(Self: PABCSystem.List; ind: integer): T; extensionmethod; -begin - Result := Self[ind]; - Self.RemoveAt(ind); -end; - -procedure add(Self: set of T; val: T); extensionmethod; -begin - Self += val; -end; - -procedure remove(Self: set of T; val: T); extensionmethod; -begin - Self -= val; + if other = nil then + raise new System.ArgumentNullException('other', 'Null object is not iterable'); + + var c1 := wrappee.Count; + var c2 := other.Count(); + + if (c1 = 0) or (c2 = 0) then + Result := true + else + begin + if c1 >= c2 then + Result := other.All(elem -> not wrappee.Contains(elem)) + else + begin + var otherSet := new HashSet(other); + Result := wrappee.All(elem -> not otherSet.Contains(elem)); + end; + end; + end; function get_keys(dct: Dictionary):= dct.keys; function get_values(dct: Dictionary):= dct.values; -function copy(Self: set of T): set of T; extensionmethod; -begin - Result := Self; -end; - -procedure clear(var st: set of T); -begin - st := []; -end; - -function __NewSetCreatorInternal(params a: array of T): NewSet; -begin - //Result._hs := new HashSet; - Result._hs.UnionWith(a); -end; - // TUPLES BEGIN function CreateTuple( v1: T1; v2: T2 @@ -436,20 +785,10 @@ function CreateTuple( // TUPLES END -function Dict(params pairs: array of (TKey, TVal)): Dictionary; -begin - Result := new Dictionary(); - for var i := 0 to pairs.Length - 1 do - Result.Add(pairs[i][0], pairs[i][1]); -end; - -function &set(sq: sequence of T): set of T; -begin - foreach var e in sq do - Result.Add(e); -end; - -function &list(sq: sequence of T): PABCSystem.List := sq.ToList(); +//function &set(sq: sequence of T): &set; +//begin +// Result := new &set(sq); +//end; function all(s: sequence of boolean): boolean; begin @@ -473,14 +812,15 @@ begin end; end; -function ToDictionary(Self: sequence of System.tuple): Dictionary; extensionmethod; +///- +function ToDictionary(Self: sequence of System.Tuple): dict; extensionmethod; begin Result := Self.ToDictionary(x->x[0],x->x[1]); end; function !empty_list(): empty_list := new empty_list(); function !empty_dict(): empty_dict := new empty_dict(); -function &set(): empty_set := new empty_set; + function round(val: real): integer := PABCSystem.round(val);