RosettaCodeData/Task/Search-a-list/Maxima/search-a-list.maxima
2023-07-01 13:44:08 -04:00

9 lines
397 B
Text

haystack: ["Zig","Zag","Wally","Ronald","Bush","Zig","Zag","Krusty","Charlie","Bush","Bozo"];
needle: "Zag";
findneedle(needle, haystack, [opt]):=block([idx],
idx: sublist_indices(haystack, lambda([w], w=needle)),
if emptyp(idx) then throw('notfound),
if emptyp(opt) then return(idx),
opt: first(opt),
if opt='f then first(idx) else if opt='l then last(idx) else throw('unknownmode));