Jump to content

Optional parameters: Difference between revisions

m
Fixed lang tags.
(→‎{{header|Perl}}: Rewrote 212.249.2.158's addition to be a bit more precise and a bit less anti-Perl.)
m (Fixed lang tags.)
Line 54:
 
GuiClose:
ExitApp</lang>
</lang>
 
=={{header|BASIC}}==
Line 454 ⟶ 453:
=={{header|Logo}}==
{{works with|UCB Logo}}
<lang logo>to sort :table [:column 1] [:ordering "before?] [:reverse "false]
<lang logo>
to sort :table [:column 1] [:ordering "before?] [:reverse "false]
; ...
end</lang>
</lang>
The function "sort" has a default arity of 1 for the required parameter. When overriding default parameters, you must wrap the call in parentheses to specify the different arity.
<lang logo>sort :table
sort :table
(sort :table 2)
(sort :table 3 "less? "true)</lang>
</lang>
 
=={{header|OCaml}}==
Line 558 ⟶ 553:
"a" "b" "c"
"" "q" "z"
>>> </lang>
 
See the Python entry in [[Named_Arguments#Python|Named Arguments]] for a more comprehensive description of Python function parameters and call arguments.
Line 578 ⟶ 573:
=={{header|R}}==
Optional parameters are given using a name=value syntax within the function header.
<lang R>tablesort <- function(x, ordering="lexicographic", column=1, reverse=false)
<lang R>
tablesort <- function(x, ordering="lexicographic", column=1, reverse=false)
{
# Implementation
Line 585 ⟶ 579:
 
# Usage is e.g.
tablesort(mytable, column=3)</lang>
</lang>
 
=={{header|Ruby}}==
Line 607 ⟶ 600:
=={{header|Slate}}==
In Slate, named optional parameters may be specified in the method signature, but not defaults, so there is a macro <tt>defaultsTo:</tt> for specifying that within the method body at run-time.
<lang slate>s@(Sequence traits) tableSort &column: column &sortBy: sortBlock &reverse: reverse
<lang slate>
s@(Sequence traits) tableSort &column: column &sortBy: sortBlock &reverse: reverse
[
column `defaultsTo: 0.
Line 615 ⟶ 607:
reverse ifTrue: [sortBlock: [| :a :b | (sortBlock applyTo: {a. b}) not]].
s sortBy: [| :a :b | sortBlock applyTo: {a at: column. b at: column}]
].</lang>
</lang>
 
=={{header|Tcl}}==
Line 725 ⟶ 716:
=={{header|XSLT}}==
You can give any template parameter a default value using the optional "select" attribute.
<lang xml><xsl:template name="sort">
<xsl:templateparam name="sorttable" />
<xsl:param name="tableordering" select="'lexicographic'" />
<xsl:param name="orderingcolumn" select="'lexicographic'1" />
<xsl:param name="columnreversed" select="1false()" />
...
<xsl:param name="reversed" select="false()" />
</xsl:template></lang>
...
</xsl:template>
</lang>
 
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.