Insert () at () of ()
2.0 Insert () at () of ().png
Category Variables
Type Stack
Introduced in 1.3

The Insert () at () of () block is a List block and a Stack block. The block inserts an item containing the given text into the list, at the given position. All values below the inserted item are passed onto the item beneath them; the last item's value is placed in a new item at the end of the list.

Example Uses

A visual representation of adding "beever" to position 3 in a list.

If a list is used for holding objects in a special order and an object has to be added, using the Add () to () block would ruin the sequence—this block, however, can insert objects without ruining the order.

Some common uses for the Insert () at () of () block:

  • Inserting items into a specific part of a list
ask [Where should I insert it?] and wait
insert [pie] at (answer) of [favorite foods v]
  • Word processors that record all characters in a list, where a character is being inserted in the middle of a sentence
  • Giving more precision than the Add () to () block

Workaround

This block requires a long process but is indeed workaroundable. In the following example there is a general workaround of the "insert" block.

//run without screen refresh
define insert (text) at (index) of (list)
delete (all v) of [handler v] //this is a list used for adding to the other list
set [i v] to (0)
repeat (length of (list)) //makes a copy
change [i v] by (1)
add (item (i) of (list)) to [handler v]
end
delete (all v) of (list)
set [i v] to (0)
repeat (length of [handler v])
if <(i) = (index)> then
add (text) to (list)
end
add (item (i) of [handler v]) to (list)
end

See Also