RosettaCodeData/Task/Menu/Langur/menu.langur

22 lines
563 B
Text
Raw Permalink Normal View History

2026-02-01 16:33:20 -08:00
val choose = fn*(entries list) {
2024-07-13 15:19:22 -07:00
if not entries: return ""
2023-07-01 11:58:00 -04:00
# print the menu
2026-04-30 12:34:36 -04:00
writeln join(map(entries, 1..len(entries), by=fn(e, i) { "{{i:2}}: {{e}}" }), delim="\n")
2023-07-01 11:58:00 -04:00
2024-07-13 15:19:22 -07:00
val idx = read(
2025-02-27 18:35:13 -05:00
prompt="Select entry #: ",
validation=fn(x) {
2024-07-13 15:19:22 -07:00
if not x -> RE/^[0-9]+$/: return false
val y = x -> number
y > 0 and y <= len(entries)
2023-07-01 11:58:00 -04:00
},
2025-02-27 18:35:13 -05:00
errmsg="invalid selection\n",
maxattempts=-1,
2024-07-13 15:19:22 -07:00
) -> number
2023-07-01 11:58:00 -04:00
2024-07-13 15:19:22 -07:00
entries[idx]
2023-07-01 11:58:00 -04:00
}
2024-07-13 15:19:22 -07:00
writeln choose(["fee fie", "eat pi", "huff and puff", "tick tock"])