User Tools

Site Tools


plato:tutor:find_command

The -find- Command

The -search- command discussed in Chapter 8 is character-string oriented and will locate `dog' even across variable or word boundaries: the β€œd” might be at the end of one word and the β€œog” at the beginning of the next word. The -find- command, in contrast, is word oriented. It will find which word contains a certain number or character string:

find 372,n1,50,n125 look ⇙ ⇩ β‡˜ ------------β‡˜ for 372 starting looking return the at n1 through location 50 words

If n1 contains 372, n125 will return the value 0; if n2 is the first word which contains 372, n125 will be 1; etc. If none of the 50 words contains 372, n125 will be set to -1. Notice that in -search- the return is 1, not 0, if the string is found immediately. This is due to the fact that in character strings we start numbering with character number 1. On the other hand, here the first word is n(1+0).

Do not use v-variables in the first two arguments of -find- because -find- makes its comparisons by integer operations. The first argument can be a character string such as `dog' or β€œdog”. You can look at every 3rd word by specifying an optional increment:

find "cat",n1,50,n125,3 β‡˜ optional

This will look for β€œcat” in nl, n4, n7, etc., and n125 would be returned 0, or 3, or 6, etc. Negative increments can be used to search backwards from the end of the list.

You can also specify that a β€œmasked equality search” be made:

find "cat",n1,50,n125,1,o777700 β‡˜ β‡˜ mask NOT optional

In this case, n125 will be zero if [(n1 $diff$ β€œcat”) $mask$ o777700] is zero. The mask specifies that only a part of the word will be examined. The increment must be specified, even if it is one, to avoid ambiguity.

There is a -findall- command which will produce a list of all of the locations where something was found, rather than producing locations one at a time.

The -exit- Command

plato/tutor/find_command.txt Β· Last modified: 2023/08/05 18:55 by Site Administrator