Difference between revisions of "Array.foldl()"
Jump to navigation
Jump to search
(Created page with "* << Z3 Home * Z3 Language Documentation * Z%5E3_Array_Manipulation_Member_Functions | Listing of Z3 Array Manipulation Member F...") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
*[[ Z%5E3_Array_Manipulation_Member_Functions | Listing of Z3 Array Manipulation Member Functions]] | *[[ Z%5E3_Array_Manipulation_Member_Functions | Listing of Z3 Array Manipulation Member Functions]] | ||
− | |||
− | At each element, SomeFunction (that can take two parameter values) are called in sequence for element from the | + | ==Array.foldl(SomFunction, SomeStartValue) == |
+ | |||
+ | At each element, SomeFunction (that can take two parameter values) are called in sequence for element from the left. The second parameter is the last value of evaluation of the given SomeFunction. For the very first element, the SomeStartValue is passed as the second parameter, if present. If no SomeStartValue is provided, it starts with the first two as the pair to start with. | ||
+ | |||
+ | |||
+ | a=1..5; | ||
+ | a.foldl( | ||
+ | function (last,x) | ||
+ | { | ||
+ | OUTPUT([last,x,(last-x)]); | ||
+ | return(last-x) | ||
+ | }, | ||
+ | 0 | ||
+ | ) | ||
+ | |||
+ | 0 1 -1 | ||
+ | |||
+ | -1 2 -3 | ||
+ | |||
+ | -3 3 -6 | ||
+ | |||
+ | -6 4 -10 | ||
+ | |||
+ | -10 5 -15 | ||
+ | |||
+ | -15 | ||
+ | |||
+ | |||
+ | a=1..5; | ||
+ | a.foldl( | ||
+ | function (last,x) | ||
+ | { | ||
+ | OUTPUT([last,x,(last-x)]); | ||
+ | return(last-x) | ||
+ | } | ||
+ | ) | ||
+ | |||
+ | 1 2 -1 | ||
+ | |||
+ | -1 3 -4 | ||
+ | |||
+ | -4 4 -8 | ||
+ | |||
+ | -8 5 -13 | ||
+ | |||
+ | -13 | ||
+ | |||
+ | |||
+ | a=1..3; | ||
+ | a.foldr(MINUS,2) | ||
+ | |||
+ | -4 (2-1-2-3) | ||
+ | |||
+ | ==See Also== | ||
+ | |||
+ | [[Array.fold()|fold ]] | ||
+ | |||
+ | [[Array.foldr()|foldr ]] |
Latest revision as of 03:58, 24 April 2020
Array.foldl(SomFunction, SomeStartValue)
At each element, SomeFunction (that can take two parameter values) are called in sequence for element from the left. The second parameter is the last value of evaluation of the given SomeFunction. For the very first element, the SomeStartValue is passed as the second parameter, if present. If no SomeStartValue is provided, it starts with the first two as the pair to start with.
a=1..5;
a.foldl(
function (last,x)
{
OUTPUT([last,x,(last-x)]);
return(last-x)
},
0
)
0 1 -1
-1 2 -3
-3 3 -6
-6 4 -10
-10 5 -15
-15
a=1..5;
a.foldl(
function (last,x)
{
OUTPUT([last,x,(last-x)]);
return(last-x)
}
)
1 2 -1
-1 3 -4
-4 4 -8
-8 5 -13
-13
a=1..3;
a.foldr(MINUS,2)
-4 (2-1-2-3)