# Plurals with Tuples

Tuples can be combined with plurals to create Relevance clauses of surprising complexity and power. The easiest combination is also the least useful. Forming plurals of tuples (of the same type) just creates a plural tuple:

Q: (1,2); (3,4)
A: 1, 2
A: 3, 4
I: ( integer, integer )

However, attempting to form a plural of tuples of different types yields an error. As we’ve already seen, plurals must always be of the same type:

Q: (1,2);("a","b")
E: Incompatible types.

Interestingly, forming a tuple of plural expressions generates a set of tuples that represents the cross product of all the component plurals:

Q: ((1; 2), ("a"; "b"), ("*"; "\$" ))
A: 1, a, *
A: 1, a, \$
A: 1, b, *
A: 1, b, \$
A: 2, a, *
A: 2, a, \$
A: 2, b, *
A: 2, b, \$
I: plural ( integer, string, string )

Tuples of plurals can also be used to search two lists for commonality. For example, suppose we have two lists of integers, and want to know what numbers are in the intersection of the lists. We can do this by using a nested whose, and then we refer to the outer list by wrapping it in a tuple:

Q: (1;2;3;4) whose (exists (it, (2;4;6;8)) whose (item 0 of it is item 1 of it))
A: 2
A: 4

The downside of this method is that the second list is bound within the ‘whose’ clause and must be recreated for every iteration. To maintain responsiveness, you should keep lists like this short.

Tuples of plurals can also be used to compare two sets of data:

Q:((1;2;3;4),(5;6;7;8)) whose (item 1 of it = 2*item 0 of it)
A: 3, 6
A: 4, 8

You can also find out just which files are in common by serially comparing the tuples of ‘new folder, old folder’:

Q: (names of files of folder "c:/") whose (exists (it, (names of files of folder
"c:/old C")) whose (item 0 of it is item 1 of it))
A: CONFIG.SYS
A: IO.SYS
A: MSDOS.SYS
A: report.txt