Optional parameters: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added whitespace and additional comments.)
Line 2,475: 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.
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>Also allowed are named parameters.
<br><br>The REXX language doesn't have any native sorting functions, so you have to write your own sorting subroutine.
<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 @. /*stemmed array is named: @. */
<lang rexx>sortStrings: procedure expose @. /*the stemmed array is named: @. */
col=1; reverse='NO'; order='LEXICOGRAPHIC' /*set some defaults.*/
col= 1 /*set some defaults (here and below). */
reverse= 'NO'
arg options
order= 'LEXICOGRAPHIC'
do j=1 for words(options); x=word(options,j)
arg options /*obtain the options (in uppercase). */

do j=1 for words(options) /*examine all the words (options). */
x= word(options, j)
select
select
when datatype(x, 'W') then col=x/1
when datatype(x, 'W') then col= x / 1 /*normalize the number. */
when pos('=', x)==0 then order=x
when pos('=', x)==0 then order= x /*has it an equal sign? */
otherwise parse var x nam '=' value
otherwise parse var x nam '=' value /*get value.*/
end /*select*/
end /*select*/
end /*j*/
end /*j*/

/*╔═══════════════════════════════════════════════════════════╗
/*╔═══════════════════════════════════════════════════════════╗
║ check for errors here: COL isn't a positive integer ···, ║
REVERSE value isn't NO or YES, ║
check for errors here: COL isn't a positive integer ···, ║
ORDER value is recognized ···
REVERSE value isn't NO or YES,
║ ORDER value is recognized ··· ║
╚═══════════════════════════════════════════════════════════╝*/
╚═══════════════════════════════════════════════════════════╝*/

... main body of string sort here ...
... 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:
An example use is:
<lang rexx>/*REXX example uses the SortStrings subroutine with optional args. */
<lang rexx>/*REXX example uses the SortStrings subroutine with some (passed) optional arguments. */

/*···define array (@.nnn) of strings here···*/

@.1= 'one'; @.2= "two"; @.3= 'three' /*define an array (@.) of strings here.*/


call sortStrings 'Reverse=no' 3
call sortStrings 'Reverse=no' 3
/*stick a fork in it, we're done.*/
/*stick a fork in it, we're all done. */</lang>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==