Menu: Difference between revisions
m
→{{header|langur}}
(→{{header|D}}: Fix type mismatch) |
Langurmonkey (talk | contribs) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 792:
try {
immutable n = input.to!int;
return typeof(return)((n >= 0 && n <= nEntries) ? n : -1);
} catch (Exception e) // Very generic
Line 805 ⟶ 806:
writefln(" %d) %s", i, entry);
"> ".write;
immutable input = readln.chomp;
immutable choice = validChoice(input, cast(int) (entries.length - 1));
if (choice.isNull)
"Wrong choice.".writeln;
Line 817 ⟶ 821:
immutable items = ["fee fie", "huff and puff",
"mirror mirror", "tick tock"];
writeln("You chose '", items.menuSelect, "'.");
}
Line 1,823 ⟶ 1,828:
=={{header|langur}}==
<syntaxhighlight lang="langur">val .select = impure
if .entries is not list: throw "invalid args"
if len(.entries) == 0: return ""
# print the menu
writeln join "\n", map(
val .idx = number read(
"Select entry #: ",
if not
val .y = number .x
.y > 0 and .y <= len(.entries)
|