September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
15
Task/Search-a-list/S-lang/search-a-list.slang
Normal file
15
Task/Search-a-list/S-lang/search-a-list.slang
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
variable haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo","Ronald"];
|
||||
|
||||
define find(needle)
|
||||
{
|
||||
variable i = where(haystack == needle);
|
||||
if (length(i)) {
|
||||
% print(sprintf("%s: first=%d, last=%d", needle, i[0], i[-1]));
|
||||
return(i[0], i[-1]);
|
||||
}
|
||||
else
|
||||
throw ApplicationError, "an exception";
|
||||
}
|
||||
|
||||
($1, $2) = find("Ronald"); % returns 3, 9
|
||||
($1, $2) = find("McDonald"); % throws ApplicationError, labelled "an exception"
|
||||
Loading…
Add table
Add a link
Reference in a new issue