Decision tables: Difference between revisions

Added PicoLisp
m (bug fix: make assertion actually test for something)
(Added PicoLisp)
Line 135:
Ensure printer software is installed
Check/replace ink</pre>
 
=={{header|PicoLisp}}==
We allow ourselves a luxurious user interface:
<lang PicoLisp>(de yes? (Cond)
(out NIL (prin (car Cond) "? "))
(in NIL
(use Reply
(loop
(setq Reply (read))
(T (member Reply '(T Y YES Yes y yes true 1))
T )
(T (member Reply '(NIL N NO No n no false 0)))
(prinl "Please answer 'Yes' or 'No'") ) ) ) )</lang>
The decision table used in the example:
<lang PicoLisp>(de *Conditions
("Printer does not print" T T T T NIL NIL NIL NIL)
("A red light is flashing" T T NIL NIL T T NIL NIL)
("Printer is unrecognised" T NIL T NIL T NIL T NIL) )
 
(de *Actions
("Check the power cable" NIL NIL T)
("Check the printer-computer cable" T NIL T)
("Ensure printer software is installed" T NIL T NIL T NIL T)
("Check/replace ink" T T NIL NIL T T)
("Check for paper jam" NIL T NIL T) )</lang>
The decision can be made directly on the condition and action data, without the need to create intermediate tables:
<lang PicoLisp>(de decide ()
(let Reply (mapcar yes? *Conditions)
(extract and
(apply pick (append *Conditions *Actions)
'(@
(unless (pick '((Flg) (<> Flg (next))) Reply)
(rest) ) ) )
(mapcar car *Actions) ) ) )</lang>
Output:
<pre>: (decide)
Printer does not print? y
A red light is flashing? y
Printer is unrecognised? n
-> ("Check/replace ink" "Check for paper jam")
 
: (decide)
Printer does not print? n
A red light is flashing? y
Printer is unrecognised? y
-> ("Ensure printer software is installed" "Check/replace ink")
 
: (decide)
Printer does not print? n
A red light is flashing? n
Printer is unrecognised? n
-> NIL</pre>
 
=={{header|Python}}==
Anonymous user