Navigation
Synopsis Get the tail element(s) from a list.
Function
  1. list[&T] tail(list[&T] lst) throws EmptyList
  2. list[&T] tail(list[&T] lst, int len) throws IndexOutOfBounds
Usage import List;
Description
  1. Return a list consisting of all but the first element of lst.
  2. Return a list consisting of the last n elements of lst.
Examples All but first element:
rascal>import List;
ok
rascal>tail([10,20,30]);
list[int]: [20,30]
Try an error case:
rascal>tail([]);
|rascal://List|(24027,958,<1194,0>,<1238,57>): EmptyList()
	at *** somewhere ***(|rascal://List|(24027,958,<1194,0>,<1238,57>))
	at tail(|stdin:///|(5,2,<1,5>,<1,7>))


Last n elements:
rascal>tail([10, 20, 30, 40, 50, 60], 3);
list[int]: [40,50,60]
Try an error case:
rascal>tail([10, 20, 30, 40, 50, 60], 10);
|rascal://List|(24988,115,<1240,0>,<1241,73>): IndexOutOfBounds(4)
	at *** somewhere ***(|rascal://List|(24988,115,<1240,0>,<1241,73>))
	at tail(|stdin:///|(31,2,<1,31>,<1,33>))



Questions
Question [1]. Computing tail(L, M) of a list with N (N > M) elements returns a list with





Question [2].
The type of tail([10, 0, -8, 8], 1) is

Question [3].
tail(["Prune", "B", "Bert", "Cumin", "Wasabi", "Pepper"],2) == 



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.