Decision tables: Difference between revisions

→‎{{header|REXX}}: rewrote the REXX program for more positive logic (as opposed to negative logice), corrected a misspelling. -- ~~~~
(Added JavaScript)
(→‎{{header|REXX}}: rewrote the REXX program for more positive logic (as opposed to negative logice), corrected a misspelling. -- ~~~~)
Line 796:
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 requirmentsrequirements 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
Line 805:
* a method of allowing the user to quit the interrogation
<lang rexx>/*REXX pgm demonstrates a decision table and possible corrective actions*/
askQ. =
askQ.1 = 'Does the printer not print?'
askQ.2 = 'Is there a red light flashing on the printer?'
askQ.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3
 
do set=1 while ask.set\==''; end /*count the number of questions. */
 
set=set-1 /*adjust SET (number of ? asked)*/
 
act.= /* Y = yes N = no not letter = don't care. */
 
/* ┌───────◄ answer to 1st question. (in upper\lower\mixed case). */
/* │┌──────◄ answer to " " 2nd question. " " " " " " */
/* ││┌─────◄ answer to " " 3rd question. " " " " " " */
/* │││ */
/* ↓↓↓ */
act.1 = 'yny' ; pos.1 = 'Check the power cable.'
act.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.'
act.3 = '..y' ; pos.3 = 'Ensure printer software is installed.'
act.4 = '.y.' ; pos.4 = 'Check/replace ink.'
act.5 = 'y.n' ; pos.5 = 'Check for paper jam.'
/* act.2 could be also be set to: ynyYNY (lower/upper/mixed case).*/
 
do i=1 for set Q.0; ans.i=asker(i); end /*getdisplay responsesquery, from theget promptsresp.*/
call asker i /*display question, get response.*/
end /*i*/
say
possible=0 /*we'll be counting possible sols*/
 
do k=1 while act.k\=='' /*filter answers via decision tab*/
 
do j=1; d=substr(act.k,j,1); upper d
jm=j//set; if jm==0 then jm=set
if d==' ' jm=j//Q.0; if jm==0 then leavejm=Q.0
if \datatype(d,=='U ') then iterateleave
if d\==ans.jm if \datatype(d,'U') then iterate k
if j==set if d\==ans.jm then leaveiterate k
set=set-1 if j==Q /*adjust SET (number of ?then asked)*/leave
end /*j*/
end end /*ij*/
say pos.k /*this could be a possible sol. */
possible=possible+1 /*count num of possible solutions*/
Line 849 ⟶ 843:
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────ASKER subroutine───────────────────*/
asker: arg ?; oops=0; Qprefix=copies('─',9) '(question' ? "of" setQ.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 ask.? /*ask the ───────── question. */
parse pull ans; parse upper var ans ansU .
if words(ans)==0 then iterate /*nothing entered? Try again. */
if abbrev('QUIT',ansU,1) then exit /*the user is tired of answering.*/
 
do forever
if (\abbrev('YES',ansU,1) & \abbrev('NO',ansu,1)) |,
if oops words(ans)\==1 then do; say; 'invalid response: ' anssay right(howTo,79); say; oops=10; end
say Qprefix Q.?; parse pull x /*ask a question (after a iterateprompt)*/
x=space(x); parse upper var x u 1 u1 2 /*u=upper(x); u1=1st endchar*/
if words(ansx)==0 then iterate /*nothing entered? Try again. */
ans.?=left(ansU,1)
if abbrev('QUIT',ansUu,1) then exit /*the user is tired of answering.*/
return
if (\abbrev('YES',ansU,1u) &| \abbrev('NO',ansu,1u)) |,& words(x)==1 then return u1
end /*forever*/</lang>
say 'invalid response: ' x; oops=1
end /*forever*/</lang>
'''output''' (a screen scraping using a DOS prompt window for the possible responses)
DECISION.REX is the REXX program that produced this output.