fix #2161
Методы расширения FillRandom для массива и матрицы Метод a.RandomElement
This commit is contained in:
parent
c6186a6b9f
commit
d31977a285
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
|||
public const string Major = "3";
|
||||
public const string Minor = "6";
|
||||
public const string Build = "2";
|
||||
public const string Revision = "2379";
|
||||
public const string Revision = "2383";
|
||||
|
||||
public const string MainVersion = Major + "." + Minor;
|
||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%MINOR%=6
|
||||
%REVISION%=2379
|
||||
%REVISION%=2383
|
||||
%COREVERSION%=2
|
||||
%MAJOR%=3
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
3.6.2.2379
|
||||
3.6.2.2383
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
!define VERSION '3.6.2.2379'
|
||||
!define VERSION '3.6.2.2383'
|
||||
|
|
|
|||
|
|
@ -10610,6 +10610,22 @@ begin
|
|||
Self[i, j] := f(i, j);
|
||||
end;
|
||||
|
||||
/// Заполняет элементы двумерного массива случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array [,] of integer; a,b: integer); extensionmethod;
|
||||
begin
|
||||
for var i := 0 to Self.RowCount - 1 do
|
||||
for var j := 0 to Self.ColCount - 1 do
|
||||
Self[i, j] := Random(a,b);
|
||||
end;
|
||||
|
||||
/// Заполняет элементы двумерного массива случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array [,] of real; a,b: real); extensionmethod;
|
||||
begin
|
||||
for var i := 0 to Self.RowCount - 1 do
|
||||
for var j := 0 to Self.ColCount - 1 do
|
||||
Self[i, j] := a + Random*(b-a);
|
||||
end;
|
||||
|
||||
/// Применяет действие к каждому элементу двумерного массива
|
||||
procedure &ForEach<T>(Self: array [,] of T; act: T -> ()); extensionmethod;
|
||||
begin
|
||||
|
|
@ -10787,6 +10803,28 @@ end;
|
|||
// Статические методы - в методы расширения: BinarySearch, ConvertAll, Find, FindIndex, FindAll,
|
||||
// FindLast, FindLastIndex, IndexOf, Contains, LastIndexOf, Reverse, Sort
|
||||
|
||||
// Дополнения март 2020: RandomElement, FillRandom
|
||||
|
||||
/// Заполняет массив случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array of integer; a,b: integer); extensionmethod;
|
||||
begin
|
||||
for var i:=0 to Self.Length-1 do
|
||||
Self[i] := Random(a,b);
|
||||
end;
|
||||
|
||||
/// Заполняет массив случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array of real; a,b: real); extensionmethod;
|
||||
begin
|
||||
for var i:=0 to Self.Length-1 do
|
||||
Self[i] := a + Random*(b-a);
|
||||
end;
|
||||
|
||||
/// Возвращает случайный элемент массива
|
||||
function RandomElement<T>(Self: array of T): T; extensionmethod;
|
||||
begin
|
||||
Result := Self[Random(Self.Length)];
|
||||
end;
|
||||
|
||||
/// Перемешивает элементы массива случайным образом
|
||||
function Shuffle<T>(Self: array of T): array of T; extensionmethod;
|
||||
begin
|
||||
|
|
|
|||
9
TestSuite/FunToObj_Overloading.pas
Normal file
9
TestSuite/FunToObj_Overloading.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function f0(x: byte) := x;
|
||||
|
||||
procedure p1(o: object) := exit;
|
||||
procedure p1(o: word) := exit;
|
||||
|
||||
begin
|
||||
p1(f0);
|
||||
Assert(True)
|
||||
end.
|
||||
|
|
@ -1262,6 +1262,8 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
else if (sem_type.IsEnum)
|
||||
return new PascalABCCompiler.SyntaxTree.named_type_reference(get_idents_from_dot_string(sem_type.name, sem_type.location), sem_type.location);
|
||||
else if (sem_type is compiled_type_node ctn1 && ctn1.compiled_type == typeof(System.IntPtr))
|
||||
return new PascalABCCompiler.SyntaxTree.named_type_reference(get_idents_from_dot_string("System.IntPtr", sem_type.location), sem_type.location);
|
||||
else
|
||||
return new PascalABCCompiler.SyntaxTree.named_type_reference(get_idents_from_dot_string(sem_type.PrintableName, sem_type.location), sem_type.location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1153,23 +1153,21 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
else
|
||||
{
|
||||
if (is_alone_method_defined)
|
||||
//issue #2161 - SSM 12.03.2020
|
||||
//issue #348
|
||||
if (formal_param_type == SystemLibrary.SystemLibrary.object_type && factparams[i].type is delegated_methods)
|
||||
{
|
||||
//issue #348
|
||||
if (formal_param_type == SystemLibrary.SystemLibrary.object_type && factparams[i].type is delegated_methods)
|
||||
{
|
||||
possible_type_convertions ptci = new possible_type_convertions();
|
||||
ptci.first = null;
|
||||
ptci.second = null;
|
||||
ptci.from = factparams[i].type;
|
||||
ptci.to = formal_param_type;
|
||||
tc.AddElement(ptci);
|
||||
factparams[i] = syntax_tree_visitor.CreateDelegateCall((factparams[i].type as delegated_methods).proper_methods[0]);
|
||||
return tc;
|
||||
}
|
||||
else
|
||||
error = new CanNotConvertTypes(factparams[i], factparams[i].type, formal_param_type, locg);
|
||||
possible_type_convertions ptci = new possible_type_convertions();
|
||||
ptci.first = null;
|
||||
ptci.second = null;
|
||||
ptci.from = factparams[i].type;
|
||||
ptci.to = formal_param_type;
|
||||
tc.AddElement(ptci);
|
||||
factparams[i] = syntax_tree_visitor.CreateDelegateCall((factparams[i].type as delegated_methods).proper_methods[0]);
|
||||
return tc;
|
||||
}
|
||||
if (is_alone_method_defined) // если мы сюда попали, то ошибка более явная
|
||||
error = new CanNotConvertTypes(factparams[i], factparams[i].type, formal_param_type, locg);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ namespace PascalABCCompiler.TreeRealization
|
|||
{
|
||||
get
|
||||
{
|
||||
return full_name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10610,6 +10610,22 @@ begin
|
|||
Self[i, j] := f(i, j);
|
||||
end;
|
||||
|
||||
/// Заполняет элементы двумерного массива случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array [,] of integer; a,b: integer); extensionmethod;
|
||||
begin
|
||||
for var i := 0 to Self.RowCount - 1 do
|
||||
for var j := 0 to Self.ColCount - 1 do
|
||||
Self[i, j] := Random(a,b);
|
||||
end;
|
||||
|
||||
/// Заполняет элементы двумерного массива случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array [,] of real; a,b: real); extensionmethod;
|
||||
begin
|
||||
for var i := 0 to Self.RowCount - 1 do
|
||||
for var j := 0 to Self.ColCount - 1 do
|
||||
Self[i, j] := a + Random*(b-a);
|
||||
end;
|
||||
|
||||
/// Применяет действие к каждому элементу двумерного массива
|
||||
procedure &ForEach<T>(Self: array [,] of T; act: T -> ()); extensionmethod;
|
||||
begin
|
||||
|
|
@ -10787,6 +10803,28 @@ end;
|
|||
// Статические методы - в методы расширения: BinarySearch, ConvertAll, Find, FindIndex, FindAll,
|
||||
// FindLast, FindLastIndex, IndexOf, Contains, LastIndexOf, Reverse, Sort
|
||||
|
||||
// Дополнения март 2020: RandomElement, FillRandom
|
||||
|
||||
/// Заполняет массив случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array of integer; a,b: integer); extensionmethod;
|
||||
begin
|
||||
for var i:=0 to Self.Length-1 do
|
||||
Self[i] := Random(a,b);
|
||||
end;
|
||||
|
||||
/// Заполняет массив случайными значениями в диапазоне от a до b
|
||||
procedure FillRandom(Self: array of real; a,b: real); extensionmethod;
|
||||
begin
|
||||
for var i:=0 to Self.Length-1 do
|
||||
Self[i] := a + Random*(b-a);
|
||||
end;
|
||||
|
||||
/// Возвращает случайный элемент массива
|
||||
function RandomElement<T>(Self: array of T): T; extensionmethod;
|
||||
begin
|
||||
Result := Self[Random(Self.Length)];
|
||||
end;
|
||||
|
||||
/// Перемешивает элементы массива случайным образом
|
||||
function Shuffle<T>(Self: array of T): array of T; extensionmethod;
|
||||
begin
|
||||
|
|
|
|||
Loading…
Reference in a new issue