langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,40 @@
REBOL [
Title: "List Indexing"
Author: oofoe
Date: 2009-12-06
URL: http://rosettacode.org/wiki/Index_in_a_list
]
locate: func [
"Find the index of a string (needle) in string collection (haystack)."
haystack [series!] "List of values to search."
needle [string!] "String to find in value list."
/largest "Return the largest index if more than one needle."
/local i
][
i: either largest [
find/reverse tail haystack needle][find haystack needle]
either i [return index? i][
throw reform [needle "is not in haystack."]
]
]
; Note that REBOL uses 1-base lists instead of 0-based like most
; computer languages. Therefore, the index provided will be one
; higher than other results on this page.
haystack: parse "Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo" none
print "Search for first occurance:"
foreach needle ["Washington" "Bush"] [
print catch [
reform [needle "=>" locate haystack needle]
]
]
print [crlf "Search for last occurance:"]
foreach needle ["Washington" "Bush"] [
print catch [
reform [needle "=>" locate/largest haystack needle]
]
]