List (Stringlist function): Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
m (syntax digram, tags and links) |
||
Line 1: | Line 1: | ||
{{Template:Stringlist:List subtitle}} | {{Template:Stringlist:List subtitle}} | ||
This shared function is a virtual constructor, or factory method, for <var> | This shared function is a virtual constructor, or factory method, for <var>sStringlists</var>. The <var>List</var> method invokes the creation of a new <var>stringlist</var> instance, then populates that instance with items that are, respectively, the values of the method arguments. | ||
==Syntax== | ==Syntax== | ||
Line 7: | Line 7: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%newlist</th> | ||
<td>A declared or existing <var> | <td>A declared or existing <var>stringlist</var> object.</td></tr> | ||
<tr><th>itemlist</th> | <tr><th>itemlist</th> | ||
<td>A comma-delimited set of strings, each of which, from left to right, becomes an item in the resultant new <var> | <td>A comma-delimited set of strings, each of which, from left to right, becomes an item in the resultant new <var>stringlist</var>, <var class="term">%newlist</var>.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li> | <li><var>list</var> requires at least one argument, which may be null.<li>If an existing <var>stringlist</var> is set to receive the result of <var>list</var>, then any existing item(s) in that <var>stringlist</var> are entirely removed before the new item(s) are added.<li>The maximum number of <var class="term">itemlist</var> values is 62.<li>See factory methods for more information.</ul> | ||
<li>If an existing <var> | |||
<li>See factory methods for more information. | |||
</ul> | |||
==Examples== | ==Examples== | ||
<ul> | <ul><li><var>List</var> 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: | ||
<li>The following <var> | <p class="output">%sl = List(<i>itemlist</i>) | ||
%sl = %(Stringlist):List(<i>itemlist</i>) | |||
%sl = %sl2:List(<i>itemlist</i>) | |||
</p> | |||
<li>The following <var>list</var> method call creates a new <var>stringlist</var> instance whose three items are, respectively, the strings <var class="term">Moe</var>, <var class="term">Larry</var>, and <var class="term">Curly</var>: | |||
<p class="code">%sl is object stringlist | <p class="code">%sl is object stringlist | ||
%sl = list('Moe', 'Larry', 'Curly') | %sl = list('Moe', 'Larry', 'Curly') | ||
</p> | </p> | ||
<li>You can use the <var> | <li>You can use the <var>list</var> method in contexts where a <var>stringlist</var> is a method parameter. For example, the <var>[[Run (Daemon function)|Run]]</var> method of the <var>daemon</var> class takes a <var>stringlist</var> object as an argument. A <var>list</var> method call can be used for such an argument, as shown below: | ||
<p class="code">%d is object daemon | <p class="code">%d is object daemon | ||
... | ... | ||
%d:run(%(stringlist):list('*LOWER', 'b', - | %d:run(%(stringlist):list('*LOWER', 'b', - | ||
'printText Whatever', 'printText More', 'end')):print | 'printText Whatever', 'printText More', 'end')):print | ||
</p> | </p> | ||
It is necessary above to specify the class < | It is necessary above to specify the class <var class="term">%(Stringlist):</var> preceding the keyword <var>list</var>, because strings are also valid in the first argument for <var>[[Run (Daemon function)|Run]]</var>, and <var>list</var>; without a qualifier it could be interpreted as a field called <var class="term">list</var>.<li> | ||
However, | However, cases where a <var>stringlist</var> argument is expected, you can specify the <var>List</var> keyword without a qualifier. For example, a user method called Stuffit takes a <var>stringlist</var> input: | ||
<p class="code">%foo:stuffit(list('Hickory', 'Dickory', 'Doc')) | <p class="code">%foo:stuffit(list('Hickory', 'Dickory', 'Doc')) |
Revision as of 07:25, 26 January 2011
Construct a new Stringlist from list of strings (Stringlist class)
This shared function is a virtual constructor, or factory method, for sStringlists. The List method 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. |
---|---|
itemlist | A comma-delimited set of strings, each of which, from left to right, becomes an item in the resultant new stringlist, %newlist. |
Usage notes
- list requires at least one argument, which may be null.
- If an existing stringlist is set to receive the result of list, then any existing item(s) in that stringlist are entirely removed before the new item(s) are added.
- The maximum number of itemlist values is 62.
- See factory methods for more information.
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, and Curly:
%sl is object stringlist %sl = list('Moe', 'Larry', 'Curly')
- 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
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. -
However, 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'))