On this page:
What’s the point?
Chatting with Someone
You Should Have Seen This Coming...
6.10

Lab 13: Chatting with Chip

Implement this lab with the BSL+. Require the HtDP2e image and universe libraries at the top of your definitions:
(require 2htdp/image)
(require 2htdp/universe)

Make sure you follow The Style we use for the {B,I,A}SL{,+} languages in this class.

Open your current ChatClient implementation from labs 6-8, 10-12. Make sure you’ve completed these labs before you continue with this lab and save/submit your definitions. We will be extending this program in future labs.

Choose the initial Head and Hands, and get started!

What’s the point?

In Lab 12: Chatting with Text we updated our ChatClient implementation to work on our new History data definition. You should have a fully working client, including properly wrapped lines of text in messages that appear in the history.

But why have a chat client without someone to chat with?

A single ChatClient isn’t enough to have a conversation. Let’s extend the state of the world to include another ChatClient.

Ex 1: Design a data definition ChatRoom to represent a conversation between two ChatClients, with fields referred to as me and other.

Note: The history of the two ChatClients is likely to be identical–don’t worry about that redundancy for this lab.

Note: If you define structures or functions that implement the ChatRoom data definition, be sure to follow The Style for their identifiers. More importantly, don’t use ChatRoom in their names (thought chat-room or the more brief chat are fine choices).

Remember, there is no BSL identifier ChatRoom and it has no meaning at run-time. Data definitions are specifications–rules we agree to when interacting with certain types of data. We agree that functions that return ChatRooms return values of the specified form. We agree to only give functions that expect ChatRooms values of the specified form.

Chatting with Someone

A ChatRoom has two parts, of course we can go ahead and...

Ex 2 Write down the template chat-template : ChatRoom -> ??? for functions that operate on ChatRooms.

Ex 3 Define two example ChatClients: CLIENT-ME and CLIENT-CHIP.

Our previous WorldState in our big-bang invocation was ChatClient. We need to define and use functions that create and manipulate our new WorldState: ChatRoom.

Ex 4: In a comment in your definitions window, write down a list of all functions that need to be written for ChatRooms.

Hint: Just as when we implemented TwoChips, don’t modify your old code that operates on ChatClients since you should be able to reuse much of it.

Note: Draw the ChatRoom as two ChatClients side-by-side.

Swap Head and Hands!

Ex 5: Get the ChatRoom with two clients up and running so that they can have a conversation.

You Should Have Seen This Coming...

Swap Head and Hands!

Ex 6: Extend the definition of ChatRoom to handle an arbitrary number of clients.

Ex 7: Get the ChatRoom with an arbitrary number of clients up and running so that they can all have a conversation.