User Tools

Site Tools


pf:prpldocs:lists

<script type="text/javascript"> function selectText(containerid) { if (document.selection) { var range = document.body.createTextRange(); range.moveToElementText(document.getElementById(containerid)); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNode(document.getElementById(containerid)); window.getSelection().addRange(range); } } </script>   <a href="#" onclick="selectText('selectable')">Select All</a><br/> Save the contents to "Lists.txt"   <div id="selectable">

=CMD
=COMMAND CreateList list
=DESC 
Creates an empty list.
=ENDDESC
=EX 
if (CreateList GetListCount eq0)
	Trace("And lo, the list was empty.")
endif
=ENDEX
=ENDCMD

=CMD
=COMMAND CreateListStartingSize (int) list
=DESC 
Creates a list containing a specified number of nulls.
=ENDDESC
=EX 
Trace(CreateListStartingSize(7)[6]) #I don't even know what the standard use case of this command is. Someone please write a better example.
=ENDEX
=ENDCMD

=CMD
=COMMAND GetListCount (list) int
=DESC 
Returns the number of entries in a list.
=ENDDESC
=EX 
Split("There are four words" " ") ->list
Trace(GetListCount(<-list))
=ENDEX
=ENDCMD

=CMD
=COMMAND GetListElement (list int) value
=DESC 
Returns the value at the specified index of a list. Lists are indexed from zero.

If a list is stored in a variable, this can be abbreviated to <-list[<-index].
=ENDDESC
=EX 
Split("1,2,3,4,5,6" ",") ->list
0 6 do
    Trace (<-list I GetListElement)
    Trace (<-list[I])
loop
=ENDEX
=ENDCMD

=CMD
=COMMAND SetListElement (list int value)
=DESC 
Stores a value at the specified index of a list. The previously stored value is overwritten.

If a list is stored in a variable, this can be abbreviated to <-value ->list[<-index].
=ENDDESC
=EX 
Split("1,2,3,4,5,6" ",") ->list
SetListElement(<-list 2 "G")
"R" ->list[4]
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND InsertListElement (list int value)
=DESC
Stores a value at the specified index of a list. The previously stored value, and all subsequent values have their indices shifted up by one.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
InsertListElement(<-list 3 "Spoon")
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND AppendToList (list value)
=DESC
Adds a value to the end of a list.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
AppendToList( <-list 7)
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND PrependToList (list value)
=DESC
Adds a value to the beginning of a list. Any values previously stored in the list are shifted up by one.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
PrependToList( <-list 0)
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND AppendStackToList (list)
=DESC
Adds all values on the stack to the end of a list. The order of the values will be reversed.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
Split("1,2,3,4,5,6" ",") <-list AppendStackToList
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND PrependStackToList (list)
=DESC
Adds all values on the stack to the beginning of a list. Any values previously stored in the list are shifted up.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
Split("1,2,3,4,5,6" ",") <-list PrependStackToList
Trace(<-list)
=ENDEX
=ENDCMD

=CMD
=COMMAND CopyList (list) list
=DESC
Creates a copy of a list with the same contents. Someone more computer-eloquent explain pass by reference vs. value here. Note that if the list contains other lists, they will not be copied - for that you need DeepCopyList.
=ENDDESC
=EX
Split("1,2,3,4,5,6" ",") ->list
<-list CopyList ->list2
SetListElement(<-list2 0 "banana")
Trace(<-list)
Trace(<-lis2)
=ENDEX
=ENDCMD

=CMD
=COMMAND DeepCopyList (list) list
=DESC
Creates a copy of a list with the same contents. Someone more computer-eloquent explain pass by reference vs. value here. If the list contains any other lists, they are also recursively deep copied.
=ENDDESC
=EX
#TODO
=ENDEX
=ENDCMD

</div>

pf/prpldocs/lists.txt · Last modified: 2016/06/24 19:06 by planetfall