"A silly example of multiple dispatching, the paper-scissors-rock game used by Bruce Eckel as an example of multiple dispatching in Java and Python (see 'Thinking in Patterns' for the Java version and 'Thinking in Python' for the Python one)." 'src/init.slate' fileIn. "First we add three objects to the lobby, for paper, scissors and rock (would name them 'classes' in a class-based language)." lobby addSlot: #paper valued: Cloneable derive. lobby addSlot: #scissors valued: Cloneable derive. lobby addSlot: #rock valued: Cloneable derive. "Then we define all the possible competitions betweens objects in p/s/r traits by means of multiple dispatching. The method returns 0 if the game is draw, 1 if the first parameter wins, 2 if the second parameter wins." _@(paper traits) compete: _@(paper traits) [ 0 ]. _@(paper traits) compete: _@(scissors traits) [ 2 ]. _@(paper traits) compete: _@(rock traits) [ 1 ]. _@(scissors traits) compete: _@(paper traits) [ 1 ]. _@(scissors traits) compete: _@(scissors traits) [ 0 ]. _@(scissors traits) compete: _@(rock traits) [ 2 ]. _@(rock traits) compete: _@(paper traits) [ 2 ]. _@(rock traits) compete: _@(scissors traits) [ 1 ]. _@(rock traits) compete: _@(rock traits) [ 0 ]. "Let's try it with a game. First we define two more slots in the lobby to hold two witnesses." lobby addSlot: #a valued: paper derive. lobby addSlot: #b valued: scissors derive. "Then we play the match. As an example: a compete: b yields 2. This was the silly adaptation of Bruce Eckel's example, without considering the fact that, since Slate is based on prototypes, we can do better. Why should we have witnesses when we can directly dispatch upon the original objects?" _@paper compete: _@paper [ 0 ]. _@paper compete: _@scissors [ 2 ]. _@paper compete: _@rock [ 1 ]. _@scissors compete: _@paper [ 1 ]. _@scissors compete: _@scissors [ 0 ]. _@scissors compete: _@rock [ 2 ]. _@rock compete: _@paper [ 2 ]. _@rock compete: _@scissors [ 1 ]. _@rock compete: _@rock [ 0 ]. "The same match as before: paper compete: scissors yields, as usual, 2. Note that we can consider paper, scissors and rocks as singletons, as symbols, as whatever. How many language do allow you to dispatch methods to *single instances*? Now let's clone the original objects:" lobby addSlot: #groucho valued: paper clone. lobby addSlot: #chico valued: scissors clone. lobby addSlot: #harpo valued: rock clone. "Try groucho compete: harpo, or groucho compete: scissors. Note how dispatching is extended to clones."