23 lines
625 B
Text
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."
|
|
)
|
|
);
|