Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #19 Reverse a list

Reverse the order of the elements of the list x.
This may reverse "in-place" and destroy the original ordering.

my @list = ('words', 'of', 'list', 'a', 'reverse');
my @reversed = reverse @list;

reverse is a built-in function. Given an array, it will reverse it. Given a string, it will return a string with the letters reversed.
with Ada.Containers.Vectors;
use Ada.Containers;
X.Reverse_Elements;

New implementation...
< >
programming-idioms.org