This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,69 @@
integer
search(list l, text s)
{
integer i;
i = 0;
while (i < l_length(l)) {
if (!compare(l_q_text(l, i), s)) {
break;
}
i += 1;
}
if (i == l_length(l)) {
i = -1;
}
return i;
}
void
search_for(list l, ...)
{
integer i;
i = 1;
while (i < count()) {
integer index;
index = search(l, $i);
o_text($i);
if (index == -1) {
o_text(" is not in the haystack\n");
} else {
o_text(" is at ");
o_integer(index);
o_text("\n");
}
i += 1;
}
}
list
new_list(...)
{
integer i;
list l;
i = 0;
while (i < count()) {
l_append(l, $i);
i += 1;
}
return l;
}
integer
main(void)
{
list l;
l = new_list("Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty",
"Charlie", "Bush", "Boz", "Zag");
search_for(l, "Bush", "Washington", "Zag");
return 0;
}

View file

@ -0,0 +1,23 @@
( 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."
)
);