Функция Matr для создания матрицы
This commit is contained in:
miks1965 2018-07-14 12:31:59 +03:00
parent 5c87179327
commit 210fa46d3f
7 changed files with 99 additions and 4 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3"; public const string Major = "3";
public const string Minor = "4"; public const string Minor = "4";
public const string Build = "0"; public const string Build = "0";
public const string Revision = "1689"; public const string Revision = "1693";
public const string MainVersion = Major + "." + Minor; public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%COREVERSION%=0 %COREVERSION%=0
%REVISION%=1689 %REVISION%=1693
%MINOR%=4 %MINOR%=4
%MAJOR%=3 %MAJOR%=3

View file

@ -1 +1 @@
!define VERSION '3.4.0.1689' !define VERSION '3.4.0.1693'

View file

@ -1781,6 +1781,8 @@ function ReadArrString(prompt: string; n: integer): array of string;
// ----------------------------------------------------- // -----------------------------------------------------
//>> Подпрограммы для матриц # Subroutines for matrixes //>> Подпрограммы для матриц # Subroutines for matrixes
// ----------------------------------------------------- // -----------------------------------------------------
/// Возвращает двумерный массив размера m x n, заполненный указанными значениями по строкам
function Matr<T>(m,n: integer; params data: array of T): array [,] of T;
/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями
function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer;
/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями
@ -2166,6 +2168,7 @@ const
PARAMETER_FROM_OUT_OF_RANGE = 'Параметр from за пределами диапазона!!The from parameter out of bounds'; PARAMETER_FROM_OUT_OF_RANGE = 'Параметр from за пределами диапазона!!The from parameter out of bounds';
PARAMETER_TO_OUT_OF_RANGE = 'Параметр to за пределами диапазона!!The to parameter out of bounds'; PARAMETER_TO_OUT_OF_RANGE = 'Параметр to за пределами диапазона!!The to parameter out of bounds';
ARR_LENGTH_MUST_BE_MATCH_TO_MATR_SIZE = 'Размер одномерного массива не согласован с размером двумерного массива!!The 1-dim array length does not match 2-dim array size'; ARR_LENGTH_MUST_BE_MATCH_TO_MATR_SIZE = 'Размер одномерного массива не согласован с размером двумерного массива!!The 1-dim array length does not match 2-dim array size';
INITELEM_COUNT_MUST_BE_EQUAL_TO_MATRIX_ELEMS_COUNT = 'Количество инициализирующих элементов не совпадает с количеством элементов матрицы!!The number of elements in init list must be equal to the number of elements in matrix';
// ----------------------------------------------------- // -----------------------------------------------------
// WINAPI // WINAPI
@ -8399,6 +8402,13 @@ begin
Result := Self Result := Self
end; end;
/// Выводит последовательность, каждый элемент отображается с помощью функции map и выводится на новой строке
function PrintLines<T,T1>(Self: sequence of T; map: T->T1): sequence of T; extensionmethod;
begin
Self.Select(map).Println(NewLine);
Result := Self
end;
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя delim в качестве разделителя /// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя delim в качестве разделителя
function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod; function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod;
begin begin
@ -8449,6 +8459,18 @@ begin
Result := Self.OrderByDescending(x -> x); Result := Self.OrderByDescending(x -> x);
end; end;
/// Возвращает отсортированную по возрастанию последовательность
function Order<T>(Self: sequence of T): sequence of T; extensionmethod;
begin
Result := Self.OrderBy(x -> x);
end;
/// Возвращает отсортированную по убыванию последовательность
function OrderDescending<T>(Self: sequence of T): sequence of T; extensionmethod;
begin
Result := Self.OrderByDescending(x -> x);
end;
/// Возвращает множество HashSet по данной последовательности /// Возвращает множество HashSet по данной последовательности
function ToHashSet<T>(Self: sequence of T): HashSet<T>; extensionmethod; function ToHashSet<T>(Self: sequence of T): HashSet<T>; extensionmethod;
begin begin
@ -9416,6 +9438,21 @@ end;
//>> Фиктивная секция YYY - не удалять! # YYY //>> Фиктивная секция YYY - не удалять! # YYY
// ----------------------------------------------------- // -----------------------------------------------------
function Matr<T>(m,n: integer; params data: array of T): array [,] of T;
begin
if data.Length<>m*n then
raise new System.ArgumentException(GetTranslation(INITELEM_COUNT_MUST_BE_EQUAL_TO_MATRIX_ELEMS_COUNT));
Result := new T[m, n];
var k := 0;
for var i:=0 to Result.RowCount-1 do
for var j:=0 to Result.ColCount-1 do
begin
Result[i,j] := data[k];
k += 1;
end;
end;
// Реализация операций с матрицами - только после введения RowCount и ColCount // Реализация операций с матрицами - только после введения RowCount и ColCount
function MatrRandom(m: integer; n: integer; a, b: integer): array [,] of integer; function MatrRandom(m: integer; n: integer; a, b: integer): array [,] of integer;
begin begin

25
TestSuite/foreachvar4.pas Normal file
View file

@ -0,0 +1,25 @@
type
t1=class
public
i1 := 55;
function f1 := 1;
end;
t2=class
public
i2 := 66;
function f2 := 2;
end;
begin
var d := new SortedDictionary<t1,t2>;
d.Add(new t1,new t2);
{foreach var a in d do writeln(a.GetType);//KeyValuePair<t1,t2>
foreach var a in d.Keys do writeln(a.GetType);//t1
foreach var a in d.Values do writeln(a.GetType);//t2}
foreach var a in d.Values do
Assert(a.i2=66);
end.

View file

@ -16865,7 +16865,22 @@ namespace PascalABCCompiler.TreeConverter
if (ct.ToString().StartsWith(IGrTstring)) if (ct.ToString().StartsWith(IGrTstring))
elem_type = ip[1]; elem_type = ip[1];
else else
elem_type = ip[0]; {
var ln = tn.ImplementingInterfaces;
elem_type = null;
foreach (var x in ln)
{
var xctn = x as compiled_generic_instance_type_node;
if (xctn != null && xctn.name.StartsWith("IEnumerable<")) // Немного грубовато.
{
elem_type = xctn.instance_params[0];
break;
}
}
if (elem_type == null)
elem_type = ip[0];
}
//var Tname = ip[0].name; //var Tname = ip[0].name;
//elem_type = convert_strong(new SyntaxTree.named_type_reference(Tname, _foreach_stmt.in_what.source_context)); //elem_type = convert_strong(new SyntaxTree.named_type_reference(Tname, _foreach_stmt.in_what.source_context));
} }

View file

@ -1781,6 +1781,8 @@ function ReadArrString(prompt: string; n: integer): array of string;
// ----------------------------------------------------- // -----------------------------------------------------
//>> Подпрограммы для матриц # Subroutines for matrixes //>> Подпрограммы для матриц # Subroutines for matrixes
// ----------------------------------------------------- // -----------------------------------------------------
/// Возвращает двумерный массив размера m x n, заполненный указанными значениями по строкам
function Matr<T>(m,n: integer; params data: array of T): array [,] of T;
/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями
function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer;
/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями
@ -2166,6 +2168,7 @@ const
PARAMETER_FROM_OUT_OF_RANGE = 'Параметр from за пределами диапазона!!The from parameter out of bounds'; PARAMETER_FROM_OUT_OF_RANGE = 'Параметр from за пределами диапазона!!The from parameter out of bounds';
PARAMETER_TO_OUT_OF_RANGE = 'Параметр to за пределами диапазона!!The to parameter out of bounds'; PARAMETER_TO_OUT_OF_RANGE = 'Параметр to за пределами диапазона!!The to parameter out of bounds';
ARR_LENGTH_MUST_BE_MATCH_TO_MATR_SIZE = 'Размер одномерного массива не согласован с размером двумерного массива!!The 1-dim array length does not match 2-dim array size'; ARR_LENGTH_MUST_BE_MATCH_TO_MATR_SIZE = 'Размер одномерного массива не согласован с размером двумерного массива!!The 1-dim array length does not match 2-dim array size';
INITELEM_COUNT_MUST_BE_EQUAL_TO_MATRIX_ELEMS_COUNT = 'Количество инициализирующих элементов не совпадает с количеством элементов матрицы!!The number of elements in init list must be equal to the number of elements in matrix';
// ----------------------------------------------------- // -----------------------------------------------------
// WINAPI // WINAPI
@ -9435,6 +9438,21 @@ end;
//>> Фиктивная секция YYY - не удалять! # YYY //>> Фиктивная секция YYY - не удалять! # YYY
// ----------------------------------------------------- // -----------------------------------------------------
function Matr<T>(m,n: integer; params data: array of T): array [,] of T;
begin
if data.Length<>m*n then
raise new System.ArgumentException(GetTranslation(INITELEM_COUNT_MUST_BE_EQUAL_TO_MATRIX_ELEMS_COUNT));
Result := new T[m, n];
var k := 0;
for var i:=0 to Result.RowCount-1 do
for var j:=0 to Result.ColCount-1 do
begin
Result[i,j] := data[k];
k += 1;
end;
end;
// Реализация операций с матрицами - только после введения RowCount и ColCount // Реализация операций с матрицами - только после введения RowCount и ColCount
function MatrRandom(m: integer; n: integer; a, b: integer): array [,] of integer; function MatrRandom(m: integer; n: integer; a, b: integer): array [,] of integer;
begin begin