RosettaCodeData/Task/Menu/Langur/menu.langur

22 lines
571 B
Text
Raw Permalink Normal View History

2024-04-19 16:56:29 -07:00
val .select = impure fn(.entries) {
if .entries is not list: throw "invalid args"
2023-07-01 11:58:00 -04:00
if len(.entries) == 0: return ""
# print the menu
2024-04-19 16:56:29 -07:00
writeln join "\n", map(fn(.e, .i) $"\.i:2;: \.e;", .entries, 1..len .entries)
2023-07-01 11:58:00 -04:00
2024-04-19 16:56:29 -07:00
val .idx = number read(
2023-07-01 11:58:00 -04:00
"Select entry #: ",
2024-04-19 16:56:29 -07:00
fn(.x) {
if not .x -> RE/^[0-9]+$/: return false
val .y = number .x
2023-07-01 11:58:00 -04:00
.y > 0 and .y <= len(.entries)
},
"invalid selection\n", -1,
)
.entries[.idx]
}
writeln .select(["fee fie", "eat pi", "huff and puff", "tick tock"])