RosettaCodeData/Task/Search-a-list/Plain-English/search-a-list.plain
2023-07-01 13:44:08 -04:00

38 lines
966 B
Text

To run:
Start up.
Make an example haystack.
Find "b" in the example haystack giving a count.
Destroy the example haystack.
Write "The index of ""b"" is " then the count on the console.
Wait for the escape key.
Shut down.
A needle is a string.
Some hay is some strings.
A bale is a thing with some hay.
A haystack is some bales.
To add some hay to a haystack:
Allocate memory for a bale.
Put the hay into the bale's hay.
Append the bale to the haystack.
To make an example haystack:
Add "a" to the example haystack.
Add "a" to the example haystack.
Add "b" to the example haystack.
Add "c" to the example haystack.
Add "d" to the example haystack.
\ As Plain English doesn't have exceptions, return -1 if the needle is not found.
To find a needle in a haystack giving a count:
Get a bale from the haystack.
Loop.
If the bale is nil, put -1 into the count; exit.
If the bale's hay is the needle, exit.
Put the bale's next into the bale.
Bump the count.
Repeat.