Optional parameters: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
(→‎{{header|REXX}}: updated REXX subroutine to use named parameters. -- ~~~~)
Line 1,330:
<br><br>The REXX language doesn't have any native sorting functions, so you have to write your own sorting subroutine.
<lang rexx>sortStrings: procedure expose @. /*stemmed array is named: @. */
col=1; reverse='NO'; order='LEXICOGRAPHIC' /*set the defaults.*/
arg col,order,options
reversearg = wordpos('REVERSE',options)
do j=1 for words(options); x=word(options,j)
if col='' then col=1
if order='' then order='LEXICOGRAPHIC'
 
select
... sort strings here ...
when datatype(x,'W') then col=x/1
when pos('=',x)==0 then order=x
otherwise parse var x nam '=' value
end /*select*/
end /*j*/
 
... main body of string sort here ...
 
return</lang>
Line 1,341 ⟶ 1,347:
<lang rexx>/*REXX example to use the SortStrings subroutine with optional args. */
/*...define array (@.nnn) of strings here...*/
call sortStrings col,, 'noReverseReverse=no' 3
col=3
call sortStrings col,,'noReverse'
/*stick a fork in it, we're done.*/</lang>