List (Stringlist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 17: Line 17:
<li>The <var>List</var> method requires at least one argument, which may be null.
<li>The <var>List</var> method requires at least one argument, which may be null.
<li>If an existing <var>Stringlist</var> is set to receive the result of the <var>List</var> method, the items in that <var>Stringlist</var> are entirely removed; then the new items are added.<li>The maximum number of '''itemlist''' values is 62.<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>If an existing <var>Stringlist</var> is set to receive the result of the <var>List</var> method, the items in that <var>Stringlist</var> are entirely removed; then the new items are added.<li>The maximum number of '''itemlist''' values is 62.<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:
<pre>
<p class="output">%sl = <var>List</var>(<i>itemlist</i></i>
%sl = <var>List</var>(<i>itemlist</i></i>
%sl = %(<var>Stringlist</var>):<var>List</var>(<i>itemlist</i></i>
%sl = %(<var>Stringlist</var>):<var>List</var>(<i>itemlist</i></i>
%sl = %sl2:<var>List</var>(<i>itemlist</i></i>
%sl = %sl2:<var>List</var>(<i>itemlist</i></i>
</pre>
</p>
<li>See factory methods for more information.
<li>See factory methods for more information.
</ul>
</ul>
Line 28: Line 27:
<ul>
<ul>
<li>The following <var>List</var> method call creates a new <var>Stringlist</var> instance whose three items are, respectively, the strings <tt>.Moe</tt>, <tt>.Larry</tt>, and <tt>.Curly</tt>:
<li>The following <var>List</var> method call creates a new <var>Stringlist</var> instance whose three items are, respectively, the strings <tt>.Moe</tt>, <tt>.Larry</tt>, and <tt>.Curly</tt>:
<pre>
<p class="code">%sl is object stringlist
%sl is object stringlist
%sl = list('Moe', 'Larry', 'Curly')
%sl = list('Moe', 'Larry', 'Curly')
</pre>
</p>
<li>You can use the <var>List</var> method in contexts where a <var>Stringlist</var> is a method parameter. For example, the Run 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:
<li>You can use the <var>List</var> method in contexts where a <var>Stringlist</var> is a method parameter. For example, the Run 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:
<pre>
<p class="code">%d is object daemon
%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
</pre>
</p>


It is necessary above to specify the class <tt>.%(<var>Stringlist</var>):</tt> preceding the keyword <tt>.<var>List</var></tt>, because <var>String</var>s are also valid in the first argument for Run, and <tt>.<var>List</var></tt> without a qualifier could be interpreted as a field called <tt>.<var>List</var></tt>.
It is necessary above to specify the class <tt>.%(<var>Stringlist</var>):</tt> preceding the keyword <tt>.<var>List</var></tt>, because <var>String</var>s are also valid in the first argument for Run, and <tt>.<var>List</var></tt> without a qualifier could be interpreted as a field called <tt>.<var>List</var></tt>.
However, in a case where a <var>Stringlist</var> argument is expected, you can specify the <tt>.<var>List</var></tt> keyword without a qualifier. For example, a user method called Stuffit takes a <var>Stringlist</var> input:
However, in a case where a <var>Stringlist</var> argument is expected, you can specify the <tt>.<var>List</var></tt> keyword without a qualifier. For example, a user method called Stuffit takes a <var>Stringlist</var> input:


<pre>
<p class="code">%foo:stuffit(list('Hickory', 'Dickory', 'Doc'))
%foo:stuffit(list('Hickory', 'Dickory', 'Doc'))
</p>
</pre>
</ul>
</ul>


[[Category:Stringlist methods|List function]]
[[Category:Stringlist methods|List function]]

Revision as of 15:47, 20 January 2011

Construct a new Stringlist from list of strings (Stringlist class)


This shared function is a virtual constructor, or factory method, for Stringlists. 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

%sl 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, %sl.

Usage notes

  • The List method requires at least one argument, which may be null.
  • If an existing Stringlist is set to receive the result of the List method, the items in that Stringlist are entirely removed; then the new items are added.
  • The maximum number of itemlist values is 62.
  • 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

  • See factory methods for more information.

Examples

  • 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 could be interpreted as a field called .List. However, in a case 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'))