List (Stringlist function): Difference between revisions
m (moved TempList (Stringlist function) to List (Stringlist function)) |
m (moved TempList (Stringlist function) to List (Stringlist function)) |
||
Line 9: | Line 9: | ||
<tr><th>%newlist</th> | <tr><th>%newlist</th> | ||
<td>A declared or existing <var>stringlist</var> object.</td></tr> | <td>A declared or existing <var>stringlist</var> object.</td></tr> | ||
<tr><th nowrap="true"><var>[%(Stringlist)]</var></th> | <tr><th nowrap="true"><var>[%(Stringlist):]</var></th> | ||
<td>The optional class name in parentheses denotes a [[Notation conventions for methods#Shared methods|virtual constructor]] method. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a <var>Stringlist</var>constructor.</td></tr> | <td>The optional class name in parentheses denotes a [[Notation conventions for methods#Shared methods|virtual constructor]] method. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a <var>Stringlist</var>constructor.</td></tr> | ||
<tr><th>itemList</th> | <tr><th>itemList</th> |
Revision as of 20:23, 30 November 2011
Construct a new Stringlist from list of strings (Stringlist class)
This shared function is a virtual constructor, or factory method, for Stringlists. List invokes the creation of a new Stringlist instance, then populates that instance with items that are, respectively, the values of the method arguments.
Syntax
%newList = [%(Stringlist):]List( itemList)
Syntax terms
%newlist | A declared or existing stringlist object. |
---|---|
[%(Stringlist):] | The optional class name in parentheses denotes a virtual constructor method. See "Usage notes", below, for more information about invoking a Stringlistconstructor. |
itemList | A comma-delimited set of strings, each of which, from left to right, becomes an item in the resultant new Stringlist, %newlist. Under Sirius Mods 7.9 and later, the items in the list could themselves be Stringlists, in which case each item in the input Stringlist is added to the target Stringlist. |
Usage notes
- List is a virtual constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null:
%sl = List(items) %sl = %(Stringlist):List(items) %sl = %sl:List(items)
- The itemList argument must contain at least one value, which may be null. The maximum number of itemList values is 62.
- If an existing Stringlist is set to receive the result of List, any existing item(s) in that Stringlist are entirely removed before the new item(s) are added.
Examples
- List is a constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null:
%sl = list(itemlist) %sl = %(Stringlist):list(itemlist) %sl = %sl2:list(itemlist)
- The following list method call creates a new stringlist instance whose three items are, respectively, the strings
Moe
,Larry
, andCurly
:%sl is object stringlist %sl = list('Moe', 'Larry', 'Curly')
- The following list method call creates a new Stringlist instance whose first three items are, respectively, the strings
Moe
,Larry
, andCurly
, and then contains a copy of all the items in Stringlist%sl2
:%sl is object stringlist %sl2 is object stringlist global %sl = list('Moe', 'Larry', 'Curly', %sl2)
- You can use the list method in contexts where a stringlist is a method parameter. For example, the Run method of the Daemon class takes a stringlist object as an argument. A list method call can be used for such an argument, as shown below:
%d is object daemon ... %d:run(%(stringlist):list('*LOWER', 'b', - 'printText Whatever', 'printText More', 'end')):print
However, in this example, it is necessary above to specify the class %(Stringlist): preceding the keyword list, because strings are also valid in the first argument for Run, and list; without a qualifier it could be interpreted as a field called list. -
In cases where a stringlist argument is expected, you can specify the List keyword without a qualifier. For example, a user method called Stuffit takes a stringlist input:
%foo:stuffit(list('Hickory', 'Dickory', 'Doc'))