RosettaCodeData/Task/Search-a-list/Bracmat/search-a-list.bracmat
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

23 lines
625 B
Text

( return the largest index to a needle that has multiple
occurrences in the haystack and print the needle
: ?list
& ( !list:? haystack [?index ?
& out$("The word 'haystack' occurs at 1-based index" !index)
| out$"The word 'haystack' does not occur"
)
& ( !list
: ? %@?needle ? !needle ?
: ( ? !needle [?index (?&~)
| ?
& out
$ ( str
$ ( "The word '"
!needle
"' occurs more than once. The last 1-based index is "
!index
)
)
)
| out$"No word occurs more than once."
)
);