List (Stringlist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (found the daemon class)
m (found the "factory methods" lnk to Virtual Constructor methods.)
Line 15: Line 15:
==Usage notes==
==Usage notes==
<ul>
<ul>
<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><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>For more information about factory methods, see <var>[[Object variables#Virtual Constructor methods|Virtual Constructor methods]]</var>.
<li>The maximum number of <var class="term">itemList</var> values is 62.
</ul>


==Examples==
==Examples==

Revision as of 05:16, 30 January 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.
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.
  • For more information about factory methods, see Virtual Constructor methods.
  • The maximum number of itemList values is 62.

Examples

  1. 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)

  2. 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')

  3. 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.
  4. 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'))

See also