pop
- command to facilitate the use of lists as stacks
- new in 1.59
- The pop or pull command can be used to retrieve values from the end of a list. To use a list as a LIFO (last in, first out) stack, simply push values onto the stack and then pop them off again in the reverse order:
push "A" onto myStack
push "B" onto myStack
pop myStack into x -- x is now "B" and "B" is deleted from myStack
pop myStack into y -- y is now "A" and "A" is deleted from myStack
The pop command can also be used to obtain values from the middle of a list, from a nested list, or to obtain multiple values at once. If a destination container is not specified, values removed from the list are put into it:
set source to "a".."z"
pop item 14 of source into x -- x is now "n"
push (A,B,C) into item 13 of source -- item 13 is now (m,A,B,C)
pop from nested item 13 of source -- sets IT to C, item 13 to (m,A,B)
pop the last three items of source into tail -- tail is now (x,y,z)
pop items (2,5,1,4) of source into z -- z is now (b,e,a,d)
- Related: push, pull, insert