Implicit matching in Icon |
|
Once a string e1 has been established as the implicit
scanning subject (&subject) within expression
e2 by use of the construct ``e1 ?
e2'', several string functions implicitly refer
to the ``current subject,'' meaning the characters of
``&subject'' starting at position
``&pos.''
any ( c )'' succeeds if the first
character of the subject is in the cset c, and
returns the position after the matched character.
many ( c )'' succeeds if there is
at least one character in c at the start of the
subject, and returns the position of
the first character of the subject that is not in the cset c.
match ( s )'' succeeds if string s
matches the beginning of the subject, and returns the position
just after the matched string.
find ( s )'' generates the positions
in the subject where string s is found.
For example, this expression
"syzygy" ? every write ( find ( "y" ) );
writes three lines with the values 2, 4, and 6, because the string
"syzygy" is established as the ``&subject'' within
the expression after the ``?'' and because the
``find()'' function uses the subject as its implicit
second argument.