Optional parameters: Difference between revisions

m
→‎{{header|REXX}}: added whitespace and additional comments.
m (→‎{{header|REXX}}: added whitespace and additional comments.)
Line 2,475:
The REXX language allows for default values for positional arguments as well as an easy method to check if a string is part of a parameter.
<br>Also allowed are named parameters.
<br><br>The REXX language doesn't have any native sorting functions, &nbsp; so you have to write your own sorting subroutine.
<lang rexx>sortStrings: procedure expose @. /*the stemmed array is named: @. */
col= 1; reverse='NO'; order='LEXICOGRAPHIC' /*set some defaults (here and below). */
reverse= 'NO'
arg options
order= 'LEXICOGRAPHIC'
do j=1 for words(options); x=word(options,j)
returnarg options /*stickobtain athe forkoptions (in it,uppercase). we're done.*/</lang>
 
do j=1 for words(options); x=word /*examine all the words (options,j). */
x= word(options, j)
select
when datatype(x, 'W') then col= x / 1 /*normalize the number. */
when pos('=', x)==0 then order= x /*has it an equal sign? */
otherwise parse var x nam '=' value /*get value.*/
end /*select*/
end /*j*/
 
/*╔═══════════════════════════════════════════════════════════╗
║ check for errors here: COL isn't a positive integer ···, ║
check for errors here: REVERSE valueCOL isn't a NO orpositive integer YES···, ║
ORDER REVERSE value isisn't NO recognized ···or YES,
║ ORDER value is recognized ··· ║
╚═══════════════════════════════════════════════════════════╝*/
 
... main body of string sort here ...
 
return /*stick a fork in it, we're done.*/</lang>
return /*stick a fork in it, we're all done. */</lang>
An example use is:
<lang rexx>/*REXX example uses the SortStrings subroutine with withsome (passed) optional argsarguments. */
 
/*···define array (@.nnn) of strings here···*/
 
@.1= 'one'; @.2= "two"; @.3= 'three' /*···define an array (@.nnn) of strings here···.*/
 
 
call sortStrings 'Reverse=no' 3
/*stick a fork in it, we're all done. */</lang>
</lang>
 
=={{header|Ruby}}==