It

The ‘it’ keyword always refers to the closest direct object or the object of the closest enclosing ‘whose’ clause, whichever is closer. There are three simple contexts in which ‘it’ has a meaning:

  • <‘it’ expression> of <direct_object>
  • phrase (<‘it’ expression>) of <direct_object>
  • (<whose_object>) whose ( <‘it’ expression> )

The first two contexts involve direct objects, the third involves a ‘whose’ clause. An example of a direct object is this expression, which lists the names and file sizes of a specified folder:

Q: (name of it, size of it) of files of folder "c:"
A: AUTOEXEC.BAT, 0
A: blacklist.txt, 42
A: boot.ini, 209
A: CONFIG.SYS, 0
…
A: whitelist.txt, 213

Here, ‘it’ refers to the ‘files of folder "c:"’.

The ‘whose’ clause lets you filter a list based on the evaluation of an ‘it’ expression. This is one of the most important targets of the ‘it’ keyword:

Q: exist files whose (name of it starts with "b") of folder "c:"
A: True
Q: number of (files whose (name of it starts with "b") of folder "c:")
A: 2

In these expressions, ‘it’ still refers to the ‘files of folder "c:"’.

You must be careful about the placement of parentheses, which can change the target of the ‘it’ keyword. In the following expression, ‘it’ refers to files:

Q: (files of folder "c:") whose (name of it contains "a")
A: "atl70.dll" "7.0.9466.0" "ATL Module for Windows (Unicode)" "7.00.9466.0" 
"Microsoft Corporation"
A: "blacklist.txt" "" "" "" ""
…

Note that this is not the same as the following Relevance expressions, which both have the wrong placement of parentheses:

Q: files of folder "c:" whose (name of it contains "a")
E: Singular expression refers to nonexistent object.
Q: files of ( folder "c:" whose (name of it contains "a") )
E: Singular expression refers to nonexistent object.

These are two equivalent (and wrong) statements where the ‘it’ refers to the closest object, which is the folder, not the files.

There can be more than one ‘it’ in an expression. The rule is that each one refers to the objects listed to the left of the associated ‘whose’. For instance:

Q: preceding texts whose (it contains "n") of characters whose (it is "a") 
of "banana"
A: ban
A: banan

Here the expression returns the substrings preceding ‘a’ that contain ‘n’. The first ‘it’ refers to the substrings; the second refers to the characters. This simple and intuitive rule makes it easy to develop complex expressions. Here’s another example:

Q: (characters of "banana") whose (exists character whose (it is "n") 
of preceding text 
of it)
A: a
A: n
A: a

This expression illustrates two nested whose-it clauses. The inner one finds leading substrings that contain an ‘n’. The outer one returns the characters following those substrings.

Since ‘it’ represents a value, you can operate on it like any other variable:

Q: (it * it) of (1;2;3;4)
A: 1
A: 4
A: 9
A: 16

You can nest these references:

Q: (it * it) whose (it > 8) of (1;2;3;4)
A: 9
A: 16

Here, the first instances of ‘it’ are multiplied and passed on to the third instance of ‘it’ for comparison.

‘It’ always refers to a single value, and never a list.