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, 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 |
col= 1 /*set some defaults (here and below). */ |
||
reverse= 'NO' |
|||
arg options |
|||
order= 'LEXICOGRAPHIC' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
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 ···, ║ |
|||
║ check for errors here: COL isn't a positive integer ···, ║ |
|||
║ 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 all done. */</lang> |
|||
An example use is: |
An example use is: |
||
<lang rexx>/*REXX example uses the |
<lang rexx>/*REXX example uses the SortStrings subroutine with some (passed) optional arguments. */ |
||
⚫ | |||
⚫ | |||
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}}== |