RosettaCodeData/Task/Search-a-list/Icon/search-a-list-1.icon
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

25 lines
852 B
Text

link lists
procedure main()
haystack := ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"] # the haystack
every needle := !["Bush","Washington"] do { # the needles
if i := lindex(haystack,needle) then { # first occurrence
write("needle=",needle, " is at position ",i," in haystack.")
if i <:= last(lindex,[haystack,needle]) then # last occurrence
write("needle=",needle, " is at last position ",i," in haystack.")
}
else {
write("needle=",needle, " is not in haystack.")
runerr(500,needle) # throw an error
}
}
end
procedure last(p,arglist) #: return the last generation of p(arglist) or fail
local i
every i := p!arglist
return \i
end