Decision tables: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.
m (added whitespace before the TOC, added a Task (bold) header.)
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
Line 1,101:
=={{header|REXX}}==
This REXX example shows how one version of a decision table could be implemented,
<br>There was additional support added to the code for:
* a &nbsp; ''no solution found'' &nbsp; message
* a &nbsp; ''don't care'' &nbsp; requirement &nbsp; (regarding the decision table)
* a method of specifying requirements and not needing recoding for future queries
* used a minimalistic way in expressing the decision table
* extra prompting when there was a user reponse error
* handles superfluous blanks and some punctuation.
* displaying of a countdown so user knows length of interrogation
* visual fidelity aids for postmortem analysis (as in logs)
* a method of allowing the user to quit the interrogation
<lang rexx>/*REXX pgm demonstrates a decision table and possible corrective actions*/
Q. =
Q.1 = 'Does the printer not print?'
Q.2 = 'Is there a red light flashing on the printer?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3
act.= /* Y = yes N = no not letter = don't care. */
 
<br>There was additional support added to the code for:
/* ┌───────◄ answer to 1st question (in upper\lower\mixed case). */
::* &nbsp; a &nbsp; ''no solution found'' &nbsp; message
/* │┌──────◄ " " 2nd " " " " " " */
::* &nbsp; a &nbsp; ''don't care'' &nbsp; requirement &nbsp; (regarding the decision table)
/* ││┌─────◄ " " 3rd " " " " " " */
::* &nbsp; a method of specifying requirements and not needing recoding for future queries
/* │││ */
::* &nbsp; used a minimalistic way in expressing the decision table
/* ↓↓↓ */
::* &nbsp; extra prompting when there was a user reponseresponse error
act.1 = 'yny' ; pos.1 = 'Check the power cable.'
::* &nbsp; handles superfluous blanks and some punctuation.
act.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.'
::* &nbsp; displaying of a countdown so user knows length of interrogation
act.3 = '..y' ; pos.3 = 'Ensure printer software is installed.'
::* &nbsp; visual fidelity aids for postmortem analysis (as in logs)
act.4 = '.y.' ; pos.4 = 'Check/replace ink.'
::* &nbsp; a method of allowing the user to quit (opt-out of) the interrogation
act.5 = 'y.n' ; pos.5 = 'Check for paper jam.'
<lang rexx>/*REXX pgmprogram demonstrates a (query) decision table and possible corrective actions.*/
Q.=; Q.1 = 'Does the printer not print?'
Q.2 = 'Is there a red light flashing on the printer?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3
actaction.= /* Y = yes N = no if character notisn't a letter = don't care. */
 
/* ┌───────◄┌─────◄── answer to 1st question (it can be in upper\lower\mixed case). */
do i=1 for Q.0; ans.i=asker(i); end /*display query, get resp.*/
/* │┌──────◄│┌────◄── " " 2nd " " " " " " " " " */
say
possible=0 /* ││┌───◄── " " 3rd " /*we'll be counting possible sols " " " " " " " " */
/* ││┌─────◄│││ " " 3rd " " " " " " */
/* │││↓↓↓ */
actaction.1 = 'yny' ; pos.1 = 'Check the power cable.'
actaction.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.'
actaction.3 = '..y' ; pos.3 = 'Ensure printer software is installed.'
actaction.4 = '.y.' ; pos.4 = 'Check/replace ink.'
actaction.5 = 'y.n' ; pos.5 = 'Check for paper jam.'
 
do ki=1 whilefor actQ.k\=='' 0; ans.i=asker(i); end /*filterdisplay answersthe viaquestion, decisionobtain tabresponse*/
/* ↓↓↓ say /*display a blank line before questions*/
possible=0 /*we'll be counting possible solutions.*/
 
do k=1 while action.k\=='' do j=1; d=substr(act.k,j,1); /*filter the answers via upperdecision dtable*/
 
do j=1; d=substr(action.k, j, 1); upper d
jm=j//Q.0; if jm==0 then jm=Q.0
if d==' ' then leave
if \datatype(d, 'U') then iterate
if d\==ans.jm then iterate k
if j==Q then leave
end /*j*/
say pos.k /*this could be a possible solsolution. */
possible=possible+1 /*count numnumber of possible solutions. */
end /*k*/
 
if possible==0 then say 'No solutions given for the information supplied.'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*───────────────────────────────────ASKER subroutine───────────────────*/
asker: arg ?; oops=0; Qprefix=copies('─', 9) '(question' ? "of" Q.0') '
howTo = '(You can answer with a Yes or No [or Quit])'
 
do forever
if oops then do; say; say right(howTo,79); say; oops=0; end
say Qprefix Q.?; parse pull x /*ask a question (after a prompt)*/
x=strip(space(x),,'.'); parse upper var x u 1 u1 2 /*u1=1st charcharacter of answer.*/
if words(x)==0 then iterate /*nothingNothing entered? Try again. */
if abbrev('QUIT',u,1) then exit /*the user is tired of answering.*/
if (abbrev('YES',u) | abbrev('"NO'",u)) & words(x)==1 then return u1
say 'invalid response: ' x; oops=1
end /*forever*/</lang>
'''output''' &nbsp; (a screen scraping using a DOS prompt window for the possible responses)
DECISION.REX is the REXX program that produced this output.
<pre style="height:50ex;overflow:scroll">
D:\►rexx decision