Decision tables: Difference between revisions
Content added Content deleted
m (added whitespace before the TOC, added a Task (bold) header.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
||
Line 1,101: | Line 1,101: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX example shows how one version of a decision table could be implemented, |
This REXX example shows how one version of a decision table could be implemented, |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Q. = |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
do i=1 for Q.0; ans.i=asker(i); end /*display query, get resp.*/ |
|||
⚫ | |||
say |
|||
/* ││┌───◄── " " 3rd " " " " " " " " " */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
do |
do i=1 for Q.0; ans.i=asker(i); end /*display the question, obtain response*/ |
||
⚫ | |||
possible=0 /*we'll be counting possible solutions.*/ |
|||
do k=1 while action.k\=='' /*filter the answers via decision table*/ |
|||
do j=1; d=substr(action.k, j, 1); upper d |
|||
jm=j//Q.0; if jm==0 then jm=Q.0 |
jm=j//Q.0; if jm==0 then jm=Q.0 |
||
if d==' ' then leave |
if d==' ' then leave |
||
if \datatype(d,'U') |
if \datatype(d, 'U') then iterate |
||
if d\==ans.jm then iterate k |
if d\==ans.jm then iterate k |
||
if j==Q then leave |
if j==Q then leave |
||
end /*j*/ |
end /*j*/ |
||
say pos.k /*this could be a possible |
say pos.k /*this could be a possible solution. */ |
||
possible=possible+1 /*count |
possible=possible+1 /*count number of possible solutions. */ |
||
end /*k*/ |
end /*k*/ |
||
if possible==0 then say 'No solutions given for the information supplied.' |
if possible==0 then say 'No solutions given for the information supplied.' |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
/*───────────────────────────────────ASKER subroutine───────────────────*/ |
|||
asker: arg ?; oops=0; Qprefix=copies('─',9) '(question' ? "of" Q.0') ' |
asker: arg ?; oops=0; Qprefix=copies('─', 9) '(question' ? "of" Q.0') ' |
||
howTo = '(You can answer with a Yes or No [or Quit])' |
howTo = '(You can answer with a Yes or No [or Quit])' |
||
do forever |
do forever |
||
if oops then do; say; |
if oops then do; say; say right(howTo,79); say; oops=0; end |
||
say Qprefix Q.?; parse pull x /*ask |
say Qprefix Q.?; parse pull x /*ask question (after prompt)*/ |
||
x=strip(space(x),,'.'); |
x=strip(space(x),,'.'); parse upper var x u 1 u1 2 /*u1=1st character of answer.*/ |
||
if words(x)==0 then iterate /* |
if words(x)==0 then iterate /*Nothing entered? Try again.*/ |
||
if abbrev('QUIT',u,1) then exit /* |
if abbrev('QUIT',u,1) then exit /*user is tired of answering.*/ |
||
if (abbrev('YES',u) |
if (abbrev('YES',u) | abbrev("NO",u)) & words(x)==1 then return u1 |
||
say 'invalid response: ' x; oops=1 |
say 'invalid response: ' x; oops=1 |
||
end /*forever*/</lang> |
end /*forever*/</lang> |
||
'''output''' (a screen scraping using a DOS prompt window for the possible responses) |
'''output''' (a screen scraping using a DOS prompt window for the possible responses) |
||
DECISION.REX is the REXX program that produced this output. |
DECISION.REX is the REXX program that produced this output. |
||
<pre style="height:50ex |
<pre style="height:50ex"> |
||
D:\►rexx decision |
D:\►rexx decision |
||