Anonymous user
Optional parameters: Difference between revisions
m
Fixed lang tags.
Underscore (talk | contribs) (→{{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>
=={{header|BASIC}}==
Line 454 ⟶ 453:
=={{header|Logo}}==
{{works with|UCB Logo}}
<lang logo>to sort :table [:column 1] [:ordering "before?] [:reverse "false]▼
▲to sort :table [:column 1] [:ordering "before?] [:reverse "false]
; ...
end</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 2)
(sort :table 3 "less? "true)</lang>
=={{header|OCaml}}==
Line 558 ⟶ 553:
"a" "b" "c"
"" "q" "z"
>>>
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)▼
▲tablesort <- function(x, ordering="lexicographic", column=1, reverse=false)
{
# Implementation
Line 585 ⟶ 579:
# Usage is e.g.
tablesort(mytable, column=3)</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▼
▲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>
=={{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:
▲ ...
▲ </xsl:template>
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}}
|