0
votes

If I input a vector and wanted to flip the elements' order, I'd write

   (reverse [1 2 3])

Now, how would I generalize this idea to be able to input nested vectors and flip the order of elements? Given a matrix A the function should reverse the elements in each column.

1
You would also want to reverse nodes? That is: [[1 2 3] [4 5 6]] would be [[6 5 4] [3 2 1]]? Or you only want leaf nodes reversed? - guilespi
Inputting the nested vector [[1 0 0] [0 2 0] [0 0 3]] would transform to [[0 0 3] [0 0 2] [1 0 0]] - sunspots
Example and description not clear. The element at the ith row and jth column ends up at which row and column? - A. Webb
@Alex: Was that supposed to be [[0 0 3] [0 2 0] [1 0 0]]? Because I'm not understanding why the 2 would move inside its vector but not anything else. - Chuck
If so...use reverse. - A. Webb

1 Answers

2
votes

Based on the example you gave in the comments, this is exactly what reverse does given a collection that contains collections. You want reverse.