Notation conventions for methods: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 8: Line 8:
<li>Special characters (square brackets, hyphens) that you do not specify because they are part of the syntax structure, not the method content
<li>Special characters (square brackets, hyphens) that you do not specify because they are part of the syntax structure, not the method content
</ul>
</ul>
For example, here is the syntax for the <var>Update</var> method of the <var>StringList</var> class:  
For example, here is the syntax for the <var>Patch</var> method of the <var>StringList</var> class:  
{{Template:Stringlist:Update syntax}}
{{Template:Stringlist:Patch syntax}}


The <var>Update</var> method accepts two arguments (the second of which is optional), updates the <var>StringList</var> that is the [[Methods#Comparing methods to complex subroutines|method object]] (<var class="term">sl</var>), and returns the updated version of that <var>StringList</var> to an object variable (<var class="term">%outList</var>).   
The <var>Patch</var> method accepts two arguments (the second of which is optional and also "named"), updates the <var>StringList</var> that is the [[Methods#Comparing methods to complex subroutines|method object]] (<var class="term">sl</var>), and returns the updated version of that <var>StringList</var> to a <var>StringList</var> object variable (<var class="term">%updList</var>).   


The following sections describe additional aspects of the syntax
The following sections describe additional aspects of the syntax.
===Mixed case===
===Mixed case===
Method names are in <b>mixed case</b> with initial and internal capital letters. <var class="product">User Language</var> keywords and variable name references are also in mixed case. This mixed-caseconvention is adhered to in text and syntax; it is not strictly adhered to in code examples. For more information about mixed-case <var class="product">User Language</var>, see [[Mixed-case User Language|"Mixed-case User Language"]].
Method names are in mixed case with initial and internal capital letters. <var class="product">User Language</var> keywords and variable name references are also in mixed case. This mixed-case convention is adhered to in text and syntax; it is not strictly adhered to in code examples. For more information about mixed-case <var class="product">User Language</var>, see [[Mixed-case User Language|"Mixed-case User Language"]].
<p></p>
<p></p>


===Optional arguments===
===Optional arguments===
In syntax, method arguments are required unless otherwise stated. Omitting a mandatory argument results in a compilation error. <b>Optional arguments</b> are enclosed in brackets (<tt>[]</tt>) in syntax and are described in text with the word "optional."
In syntax, method arguments are required unless otherwise stated. Omitting a mandatory argument results in a compilation error. Optional arguments are enclosed in brackets (<tt>[]</tt>) in syntax and are described in text with the word "optional."
===Named parameters===
===Named parameters===
Some method arguments may be passed by name; they are specified with a following equal sign (<tt>=</tt>) in method syntax diagrams. For arguments described as <b>name allowed</b> (or <b>name required</b>), you may specify (or must specify) the argument name along with the argument value when you invoke the method. You specify such argument name and value pairs in the form:
Some method arguments may be passed by name; they are specified with a following equal sign (<tt>=</tt>) in method syntax diagrams. For arguments described as "name allowed" (or "name required"), you may specify (or must specify) the argument name along with the argument value when you invoke the method. You specify such argument name and value pairs in the form:
<p class="syntax"><span class="literal">methodname</span><span class="literal">(</span> <span class="term">argName</span><span class="literal">=</span><span class="term">argValue</span> <span class="literal">)</span></p>
<code>object:methodname(... argName=argValue ...)</code>. For example, the <var>Stringlist</var> method <var>RegexCapture</var> has two optional arguments whose names are required if you specify the argument:
 
<p class="syntax"><span class="term">sl</span><span class="literal">:[[RegexCapture (Stringlist function)|RegexCapture]]</span><span class="literal">(</span> <span class="term" title="String">string</span><span class="comma">,</span> <span class="term" title="String">regex</span><span class="comma">,</span> <span class="squareb">[</span><span class="literal" title="String">Options=</span> <span class="term" title="String">string</span><span class="squareb">]</span><span class="comma">,</span> <span class="squareb">[</span><span class="literal" title="%output">Status=</span> <span class="term" title="%output">%output</span><span class="squareb">]</span><span class="literal">)</span></p>
 
Whether an argument name is a "named parameter" is declared for the method within the class definition with the <var>NameAllowed</var> or <var>NameRequired</var> keyword.
Whether an argument name is a "named parameter" is declared for the method within the class definition with the <var>NameAllowed</var> or <var>NameRequired</var> keyword.
<p></p>
 
===Callable methods===
===Callable methods===
Many functions that return a result may also be invoked by the keyword <var>Call</var>. The descriptions of such functions say that they are <b>callable</b> and display a bracketed %variable and equals sign in syntax. For example:
Many functions that return a result may also be invoked by the keyword <var>Call</var>. The descriptions of such functions say that they are "callable" and display a bracketed %variable and equals sign in syntax. For example:
{{Template:Stringlist:Add syntax}}
{{Template:Stringlist:Add syntax}}
The <var>Call</var> keyword is almost always optional, so a callable method can usually be invoked by simply specifying the method object followed by colon (<tt>:</tt>) and the method name:
The <var>Call</var> keyword is almost always optional, so a callable method can usually be invoked by simply specifying the method object followed by colon (<tt>:</tt>) and the method name:
<p class="code">Call %sl:Add('the end')</p>
<p class="code">Call %sl:Add('the end')</p>
===Shared methods===
===Shared methods===
Methods are non-shared unless otherwise identified. A <b>shared method</b> is recognizable by the <code>%(classname):</code> notation preceding the method name in the method syntax, which implies that the method need not operate on a particular object. For example:
Methods are non-shared unless otherwise identified. A shared method is recognizable by the <code>%(classname):</code> notation preceding the method name in the method syntax, which implies that the method need not operate on a particular object. For example:
<p class="code">%max = %(Stringlist):MaxItemLength
<p class="code">%max = %(Stringlist):MaxItemLength
</p>
</p>

Revision as of 20:54, 8 March 2011


The syntax for each Janus SOAP method is displayed in the form of a usage statement which shows how you specify a typical invocation of the method (and receive its result, if any). The syntax includes:

  • Keywords and placeholder words
  • Punctuation literals (parentheses, colons, etc. that you must specify)
  • Special characters (square brackets, hyphens) that you do not specify because they are part of the syntax structure, not the method content

For example, here is the syntax for the Patch method of the StringList class:

%updList = sl:Patch( patchList, [Options= string])

The Patch method accepts two arguments (the second of which is optional and also "named"), updates the StringList that is the method object (sl), and returns the updated version of that StringList to a StringList object variable (%updList).

The following sections describe additional aspects of the syntax.

Mixed case

Method names are in mixed case with initial and internal capital letters. User Language keywords and variable name references are also in mixed case. This mixed-case convention is adhered to in text and syntax; it is not strictly adhered to in code examples. For more information about mixed-case User Language, see "Mixed-case User Language".

Optional arguments

In syntax, method arguments are required unless otherwise stated. Omitting a mandatory argument results in a compilation error. Optional arguments are enclosed in brackets ([]) in syntax and are described in text with the word "optional."

Named parameters

Some method arguments may be passed by name; they are specified with a following equal sign (=) in method syntax diagrams. For arguments described as "name allowed" (or "name required"), you may specify (or must specify) the argument name along with the argument value when you invoke the method. You specify such argument name and value pairs in the form: object:methodname(... argName=argValue ...). For example, the Stringlist method RegexCapture has two optional arguments whose names are required if you specify the argument:

sl:RegexCapture( string, regex, [Options= string], [Status= %output])

Whether an argument name is a "named parameter" is declared for the method within the class definition with the NameAllowed or NameRequired keyword.

Callable methods

Many functions that return a result may also be invoked by the keyword Call. The descriptions of such functions say that they are "callable" and display a bracketed %variable and equals sign in syntax. For example:

[%number =] sl:Add( itemList)

The Call keyword is almost always optional, so a callable method can usually be invoked by simply specifying the method object followed by colon (:) and the method name:

Call %sl:Add('the end')

Shared methods

Methods are non-shared unless otherwise identified. A shared method is recognizable by the %(classname): notation preceding the method name in the method syntax, which implies that the method need not operate on a particular object. For example:

%max = %(Stringlist):MaxItemLength

Using the class name in this way denotes that the method is shared, and it models one way you can invoke the method. You can also invoke shared methods using the %objectVariable: notation used by non-shared, or instance, methods. For example, if %sl is a Stringlist object, the following statement assigns the same value to %max as in the preceding example statement:

%max = %sl:MaxItemLength

In this case, %sl indicates the class to which the method belongs, not that the method operates on %sl (which may even be null for a shared method invocation).