Anonymous user
Decision tables: Difference between revisions
Updated first D entry
m (→{{header|REXX}}: added support for superfluous blanks in answer. -- ~~~~) |
(Updated first D entry) |
||
Line 196:
<lang d>import std.stdio, std.algorithm, std.exception, std.array;
immutable struct DecisionTable {
alias immutable(bool)[] IBA;
const string[] conds, actions;
Line 204:
in size_t newLen)
pure nothrow {
result[0 .. b.length] = b[];
return
}
this(
immutable string[] a,
conds = c;
actions = a;
Line 217 ⟶ 218:
r[growTo(p[0], conds.length)] =
growTo(p[1], actions.length);
rules =
}
Line 226 ⟶ 227:
auto iTested = growTo(tested, conds.length);
if (iTested in rules)
foreach (immutable i, immutable
if (e)
rightActions ~= actions[i];
if (!rightActions.empty)
Line 241 ⟶ 243:
string answer = "no";
try
answer = stdin.readln
catch (StdioException)
writeln("no");
Line 253 ⟶ 255:
void main() {
enum { F = false, T = true }
immutable d = immutable(DecisionTable)(
["Printer is unrecognised",
"A red light is flashing",
Line 274 ⟶ 276:
);
d.consult
}</lang>
{{out}}
|