Bug #3362

Updated by Michael Kay over 6 years ago

After calling reverse($var), the value of $var is changed to be in reverse order. 

 reverse is implemented as @arg[0].expand().reverse()@ arg[0].expand().reverse() where @arg[0]@ arg[0] is an iterator. The problem is that (a) if @arg[0]@ arg[0] is a ForArray iterator, then @expand()@ expand() returns the original array, and (b) the Javascript function @reverse()@ reverse() modifies its argument in-situ. 

 So the code needs to ensure that the array is copied before calling @reverse()@, reverse(), or perhaps to avoid the @expand()@ expand() operation and prepend each item returned by the iterator to a target array. 

 (Reported informally by John Lumley)