User Tools

Site Tools


pf:prpldocs:lists

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pf:prpldocs:lists [2016/06/23 17:20] – created virgilwpf:prpldocs:lists [2025/02/14 14:57] (current) – external edit 127.0.0.1
Line 22: Line 22:
  
 =CMD =CMD
-=COMMAND TODO+=COMMAND CreateList list
 =DESC  =DESC 
-TODO+Creates an empty list.
 =ENDDESC =ENDDESC
 =EX  =EX 
-TODO+if (CreateList GetListCount eq0) 
 + Trace("And lo, the list was empty."
 +endif
 =ENDEX =ENDEX
 =ENDCMD =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
 </code> </code>
 <html></div></html> <html></div></html>
pf/prpldocs/lists.1466702431.txt.gz · Last modified: 2025/02/14 14:56 (external edit)