Developer Documentation Library > UNICOM Intelligence Function Library > List functions > Rev
 
Rev
This function returns an array containing copies of items from the input list, either in the normal order or in reverse order. The <count> parameter defines how many items from the input list are included in the returned list.
Syntax
Rev(<list> [, <count> [, <policy> [, <seed>]]])
Parameters
<list>
Type: None
Array, collection, or Categorical value to operate on.
<count>
Type: Long
(Optional.) Number of items to return. If omitted, negative, or greater than the number of input items, all items are returned.
<policy>
Type: Long
(Optional.) Controls the way the list order is chosen. See Possible values for Policy. The default value is 1.
<seed>
Type: Long
(Optional.) The state to be used for the reversal. The default value is 0.
(return)
Type: None
An array consisting of a copy of the input list.
Notes
An error occurs if <list> is a collection that does not support the For Each...Next syntax. When <list> is a collection object, the return value is an array that contains copies of the objects in the collection and the input collection object is unchanged. Because the return value is an array, it does not have a <count> property.
This function uses the reversal state stored by the mrScriptBasic engine or Evaluate component and passed as a hidden parameter. However, when both <policy> and <seed> are nonzero, the reversal state is set to <seed> before the <policy> is applied. If the resulting reversal state is even, the list is presented in normal order; if odd, the list is reversed.
The Rev function is similar to using the rev keyword in Quancept.
Possible values for Policy
0
No reversal and the reversal state is set to 0.
1
The reversal state is used without changing it.
2
The reversal state is incremented by one and used.
3
Use the starting point of the random number generator and update both the reversal state and the random number generator starting point.
Example
This example uses Rev with museums (which is a multiple response variable in the UNICOM Intelligence Data File version of the Museum sample data set) in an SQL query. The example uses the Rev function four times, each time using a different value for the Policy parameter.
SELECT museums AS Museums,
Rev(museums, , 0) AS Policy0,
Rev(museums, , 1) AS Policy1,
Rev(museums, , 2) AS Policy2,
Rev(museums, , 3) AS Policy3
FROM vdata WHERE museums.AnswerCount() > 2
Here are the results for the first five respondents:
Museums Policy0 Policy1 Policy2 Policy3
------------- ------------ ------------- ------------- ------------
1 {25,28,29} {25,28,29} {25,28,29} {29,28,25} {25,28,29}
2 {26,28,29,30} {26,28,29,30} {26,28,29,30} {26,28,29,30} {26,28,29,30}
3 {25,26,27} {25,26,27} {25,26,27} {27,26,25} {27,26,25}
4 {25,28,30} {25,28,30} {25,28,30} {25,28,30} {30,28,25}
5 {25,26,27} {25,26,27} {25,26,27} {27,26,25} {25,26,27}
In column 1, Museums, the responses are presented as they are stored in the variable, which is the “normal” order. The responses are also presented in the normal order in the next two columns:
Column 2, Policy0, presents the responses in the normal order because <policy> is set to 0 and <seed> is not specified. This means that the list is presented in the normal order.
Column 3, Policy1, presents the responses in the normal order because <policy> is set to 1 and <seed> is not specified. This means that whether the list is reversed or not is determined by the current setting of the reversal state. However, because the <seed> parameter has not been specified, the reversal state defaults to 0, which is an even number, and so the list is presented in the normal order. If we changed the query to specify the <seed> parameter as 1, the order would be reversed, because 1 is an odd number.
Column 4, Policy2, shows the list in normal and reverse order alternately. This is because <policy> is set to 2, which means that each time the function is called, one is added to the reversal state, thus causing it to alternate between odd and even values.
In the Policy3 column, the list is in normal and reverse orders at random because <policy> is set to 3. This means that the reversal state is set to a random value each time the function is called. This means that the list is in normal and reverse order randomly.
See also
RevSequence
List functions