![]() |
|
Navigation |
Synopsis Insert an element at a specific position in a list.
Function
list[&T] insertAt(list[&T] lst, int n, &T elm) throws IndexOutOfBounds
Usage
import List;
Description Returns a new list with the value of
elm inserted at index position n of the old list.
Examples
rascal>import List; ok rascal>insertAt([1,2,3], 1, 5); list[int]: [1,5,2,3] rascal>insertAt(["zebra", "elephant", "snake", "owl"], 2, "eagle"); list[str]: ["zebra","elephant","eagle","snake","owl"]An exception is thrown when the index position is outside the list: rascal>insertAt([1,2,3], 10, 5);
|rascal://List|(7109,1036,<335,0>,<379,83>): IndexOutOfBounds(10)
at *** somewhere ***(|rascal://List|(7109,1036,<335,0>,<379,83>))
at insertAt(|stdin:///|(22,1,<1,22>,<1,23>))
Questions
Question [1].
![]() ![]() N elements, the new list has
Question [2].
![]() ![]()
Question [3].
![]() ![]() ![]() |