11.6.  Exercise: Generics

[ fromfile: ex-generics.xml id: ex-generics ]

  1. Write a program that repeatedly asks the user to enter relationships or commands, and keeps track of relationships between all pairs of symbols that it sees. The interface should be pretty simple: The user enters a string that is parsed and processed by the dispatching function, processLine(). In other words, processLine() should expect strings of the following forms.

    1. To add a frop between two strings: string1=string2

    2. To list the friends of string1: string1 (no = symbol in the line)

  2. Add another function, takeback(int n), where n refers to the nth assertion. If the nth assertion added a frop, the function should "undo" that assertion, ensuring that relational integrity is kept. After this, show the updated friend lists of both symbols (string1 and string2) involved.

    Have the processLine() function scan for messages of the form "takeback n" and call the takeback() function in response.



[56] Transitivity is a third property of boolean operators that we are not assuming – for any symbols s, t, and u in S, if s op t and t op u are both true, then s op u is also true.

If a boolean operator op is Reflexive, Symmetric, and Transitive, then it is an Equivalence Relation.