Product для последовательностей
This commit is contained in:
parent
38d94f702d
commit
16970b7b3d
|
|
@ -1,5 +1,5 @@
|
||||||
begin
|
begin
|
||||||
var a := new List<integer>(arr(1, 2));
|
var a: object := new List<integer>(arr(1, 2));
|
||||||
match a with
|
match a with
|
||||||
integer(var c): write(1);
|
integer(var c): write(1);
|
||||||
boolean(var s): write(2);
|
boolean(var s): write(2);
|
||||||
|
|
|
||||||
3
TestSuite/ArrProduct.pas
Normal file
3
TestSuite/ArrProduct.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
begin
|
||||||
|
Assert(Arr(1,2,3).Product = 6);
|
||||||
|
end.
|
||||||
|
|
@ -3540,13 +3540,6 @@ namespace PascalABCCompiler.TreeConverter
|
||||||
|
|
||||||
public override void visit(SyntaxTree.class_definition _class_definition)
|
public override void visit(SyntaxTree.class_definition _class_definition)
|
||||||
{
|
{
|
||||||
/*var tt = _class_definition.DescendantNodes().OfType<class_definition>();
|
|
||||||
if (tt.Count() > 0)
|
|
||||||
{
|
|
||||||
AddWarning(new Errors.CompilerWarning("bs", _class_definition.source_context.FileName));
|
|
||||||
AddError(get_location(tt.First()),"NESTED_RECORD_DEFINITIONS_ARE_FORBIDDEN");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
var testIsTypeclassInstance = context._ctn?.Attributes?.Any(a => a.AttributeType.name == "__TypeclassInstanceAttribute");
|
var testIsTypeclassInstance = context._ctn?.Attributes?.Any(a => a.AttributeType.name == "__TypeclassInstanceAttribute");
|
||||||
if (testIsTypeclassInstance.HasValue && testIsTypeclassInstance.Value)
|
if (testIsTypeclassInstance.HasValue && testIsTypeclassInstance.Value)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8581,6 +8581,22 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
/// Возвращает произведение элементов последовательности
|
||||||
|
function Product(Self: sequence of real): real; extensionmethod;
|
||||||
|
begin
|
||||||
|
Result := 1.0;
|
||||||
|
foreach var x in Self do
|
||||||
|
Result *= x;
|
||||||
|
end;
|
||||||
|
|
||||||
|
/// Возвращает произведение элементов последовательности
|
||||||
|
function Product(Self: sequence of integer): integer; extensionmethod;
|
||||||
|
begin
|
||||||
|
Result := 1;
|
||||||
|
foreach var x in Self do
|
||||||
|
Result *= x;
|
||||||
|
end;
|
||||||
|
|
||||||
/// Возвращает отсортированную по возрастанию последовательность
|
/// Возвращает отсортированную по возрастанию последовательность
|
||||||
function Sorted<T>(Self: sequence of T): sequence of T; extensionmethod;
|
function Sorted<T>(Self: sequence of T): sequence of T; extensionmethod;
|
||||||
begin
|
begin
|
||||||
|
|
@ -9602,6 +9618,22 @@ begin
|
||||||
Self[i, j] := f(i, j);
|
Self[i, j] := f(i, j);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
/// Применяет действие к каждому элементу двумерного массива
|
||||||
|
procedure &ForEach<T>(Self: array [,] of T; act: T -> ()); extensionmethod;
|
||||||
|
begin
|
||||||
|
for var i := 0 to Self.RowCount - 1 do
|
||||||
|
for var j := 0 to Self.ColCount - 1 do
|
||||||
|
act(Self[i, j]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
/// Применяет действие к каждому элементу двумерного массива
|
||||||
|
procedure &ForEach<T>(Self: array [,] of T; act: (T,integer,integer) -> ()); extensionmethod;
|
||||||
|
begin
|
||||||
|
for var i := 0 to Self.RowCount - 1 do
|
||||||
|
for var j := 0 to Self.ColCount - 1 do
|
||||||
|
act(Self[i, j],i,j);
|
||||||
|
end;
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
//>> Фиктивная секция YYY - не удалять! # YYY
|
//>> Фиктивная секция YYY - не удалять! # YYY
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue