Anonymous user
Optional parameters: Difference between revisions
→{{header|Tcl}}: note on language conventions, minor formatting improvements
m (→{{header|Fortran}}: a little enhancement) |
(→{{header|Tcl}}: note on language conventions, minor formatting improvements) |
||
Line 229:
In Tcl, optional arguments are collected when the last argument
to a proc definition is called "args". The ''lsort'' command has a similar API, but with different keywords, so we adapt them.
By convention, optional parameter names in Tcl start with a leading “<tt>-</tt>” character.
<lang Tcl>package require Tcl 8.5
Line 235 ⟶ 237:
array set opt $args
set pars [list -index $opt(-column)]
if {$opt(-reverse)} {lappend pars -decreasing}
if {$opt(-ordering) ne ""} {lappend pars -command $opt(-ordering)}
lsort {*}$pars $table
}
# --> {"" q z} {a b c} {zap zip Zot}
# --> {a b c} {"" q z} {zap zip Zot}
# --> {"" q z} {a b c} {zap zip Zot}
# --> {zap zip Zot} {a b c} {"" q z}
}]
# --> {zap zip Zot} {a b c} {"" q z}</lang>
|