Difference between revisions of "Array.foldr()"

From ZCubes Wiki
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...")
 
 
(2 intermediate revisions by one other user not shown)
Line 49: Line 49:
  
 
-5
 
-5
 +
 +
1..3.foldr(DIVIDE,10)
 +
 +
1.6666666666666667
 +
 +
which is 10/3/2
 +
 +
==See Also==
 +
 +
[[Array.foldl()|foldl ]]
 +
 +
[[Array.fold()|fold ]]

Latest revision as of 04:05, 24 April 2020

Array.foldr(SomFunction, SomeStartValue)

At each element, SomeFunction (that can take two parameter values) are called in sequence for element from the right. 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 last two as the pair to start with.


a=1..5; a.foldr( function (last,x) { OUTPUT([last,x,(last-x)]); return(last-x) }, 0 )

0 5 -5

-5 4 -9

-9 3 -12

-12 2 -14

-14 1 -15

-15


a=1..5; a.foldr( function (last,x) { OUTPUT([last,x,(last-x)]); return(last-x) } )

5 4 1

1 3 -2

-2 2 -4

-4 1 -5

-5

1..3.foldr(DIVIDE,10)

1.6666666666666667

which is 10/3/2

See Also

foldl

fold