Decision tables: Difference between revisions
eliminate overly long lines, and dependence on invisible tab character
(bug fix) |
(eliminate overly long lines, and dependence on invisible tab character) |
||
Line 4:
=={{header|J}}==
'''Solution''':<lang j>require'strings'
▲ Printer is unrecognised Y N Y N Y N Y N
Check the power cable X ▼
Check the printer-computer cable X X ▼
Ensure printer software is installed X X X X ▼
Check/replace ink X X X X ▼
Check for paper jam X X ▼
)
'ACTION_NAMES ACTIONS'=: |:':'&cut;._2 noun define
)
assert (-:~)|: 'Y' =/&;: rules
RULE_TABLE=: (,/'X'=/&;: ACTIONS) /:&|: 'Y' =/&;: rules
troubleshoot =: verb define
RULE_TABLE troubleshoot~
:
'
smoutput 'Having trouble? Let''s track down the problem:'
(,~ ('/'cut'Suggested resolutions:/Solution unknown.') {::~ 0=#) options
)</lang>
'''Example''' (''solution found''):<lang j> troubleshoot ''
Having trouble? Let's track down the problem:
Y
Y
Y
Suggested resolutions:
'''Example''' (''solution not found''):<lang j> troubleshoot ''
Having trouble? Let's track down the problem:
Line 53 ⟶ 54:
=== Comments ===
The only interesting line in this solution is the one that assigns <tt>RULE_TABLE</tt>. The rest is mostly ancillary support.
For large numbers of rules and few actions, J's native support of sparse arrays might provide a performance advantage, particularly in space. A minor note about the implementation here: the verb (function) <tt>troubleshoot</tt> is generalized, and reusable on any set of rule table, questions, and suggested actions. The default is to use those given in the printer troubleshooting table.
|