~~NOTOC~~
<=[[4rpl:start| Index]] \\
<=[[4rpl:start#lists| Lists]]
====== List ======
List ->list
===== Description =====
Creates a list and populates it with the contents of the stack. The entire contents of the stack will be added to a newly created list.
The top item on the stack will be the last item in the list.
===== Examples =====
List(1 2 3) ->list
trace(GetListCount(<-list)
When building a list, there is a risk that there are items left on the stack before you start building your list. If you know your list length, then you can use listN. If you don't, then you need to clear the stack before starting to build your new list. __To prevent this:__ ClearStack will throw away the old stack, but if you want to save the old stack instead, then you can use the functions below.
"various" "things" "left" "on" "the stack"
@saveOldStack
List(1 2 3) ->list
@loadOldStack
traceallsp
:saveOldStack
stacksize if list ->oldStack 0 else 1 endif ->noOldStack
:loadOldStack
<-noOldStack if return endif
stacksize if list ->newStack 1 else 0 endif ->newStackSaved
<-oldStack ListToStack
<-newStackSaved if <-newStack ListToStack endif
<=[[4rpl:start| Index]]