Skip to content

Commit

Permalink
function Flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
martok committed Nov 13, 2011
1 parent 1dc47a3 commit 0528d0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Listen/Daten:
Verkettet zwei Listen zu einer neuen
* `Each(list, var, expr)`
Führt `expr` in einem neuen Kontext auf jedem Element von `list` als Variable `var` aus
* `Flatten(list)`
Kopiert jedes Element von `list` in Ergebnis (zum Umwandeln von RangeList in FixedList)
* `Aggregate(list, agg, init, var, expr)`
Wendet `expr` auf jedes Element in `list` als `var` an. Dabei kann `agg` (vorbelegt mit `init`) modifiziert werden.
Rückgabewert ist der Wert von `agg`.
Expand Down
16 changes: 16 additions & 0 deletions uMath.pas
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ TE_FunctionCall = class(TExpression)
function L_N(Context: TContext; args: TExprList): IValue;
function Range_3(Context: TContext; args: TExprList): IValue;
function Each_3(Context: TContext; args: TExprList): IValue;
function Flatten_1(Context: TContext; args: TExprList): IValue;
function Aggregate_5(Context: TContext; args: TExprList): IValue;
function Merge_2(Context: TContext; args: TExprList): IValue;
end;
Expand Down Expand Up @@ -1748,6 +1749,21 @@ function TE_FunctionCall.Each_3(Context: TContext; args: TExprList): IValue;
end;
end;

function TE_FunctionCall.Flatten_1(Context: TContext; args: TExprList): IValue;
var list:IValueList;
i:integer;
res: IValueList;
begin
if not Supports(args[0].Evaluate(Context), IValueList, list) then
raise EMathSysError.Create('Function Flatten requires a list to work on');

res:= TE_FixedList.Create;
res.Length:= list.Length;
for i:= 0 to list.length-1 do
res.ListItem[i]:= list.ListItem[i];
Result:= res as IValue;
end;

function TE_FunctionCall.Aggregate_5(Context: TContext; args: TExprList): IValue;
var list:IValueList;
agg: IExpression; //TE_ExprRef
Expand Down

0 comments on commit 0528d0a

Please sign in to comment.