6.10

Assignment 9b

home work!

Programming Language ISL

Due Date: Monday (11/06) Thursday (11/09) at 9:00pm (Week 9) This is the final extension on this project; no further changes will be made.

Purpose To integrate new functionality into a refactored program, and complete the Forum project.

Forum Exercises – Summary

Stage 4 – Receiving "REPLY" messages: Complete your on-receive handler to handle "REPLY" ServerMsgs.

Stage 5 – New views: Split your existing views into the following four:
; A World is one of
; - Viewall    <<=== user is browsing all posts
; - Threadview <<=== user is viewing a post and its replies
; - Newitem    <<=== user is creating a new post or reply
; - Search     <<=== user is searching for matching posts

Stage 6 – New user interaction: Posting versus Replying Change the keyhandler in the Viewall view to let the user enter commands:

; A Command is a string of the form
;  "catchup"                      <<=== send the "CATCHUP" message
;  "new"                          <<=== start creating a new post
;  "reply ", followed by a number <<=== start replying to the post with that ID#
;  "view ", followed by a number  <<=== view the full thread of post of that ID#

Forum Exercises – More details

Stage 4 – Receiving "REPLY" messages: Complete your on-receive handler to handle "REPLY" ServerMsgs. Use the add-reply function you designed in Assignment 9a.

Stage 5 – New views: Assignment 7a had two views: EditviewPosts mode and SearchPosts mode. We need to break apart EditviewPosts into separate views now, which means revising our data definitions:
; A World is one of
; - Viewall
; - Threadview
; - Newitem
; - Search
; INTERPRETATION: Represents four different "views" in your program.
 
; A Viewall is a (make-viewall String History)
; INTERPRETATION: The user is viewing all posts (but not replies),
;   and possibly typing a Command.
; A Threadview is a (make-threadview Post History)
; INTERPRETATION: The user is viewing a specific Post and its replies.
; A Newitem is a (make-newitem [Maybe Natural] String History)
; INTERPRETATION: The user is entering a new post (if the maybe is #false),
;   or a new reply (if the maybe is a number).  
; A Search is a (make-search History String)
; INTERPRETATION: The user is trying to view only a subset
;   of the existing messages.

Viewall mode is most similar to the existing EditviewPosts mode. It no longer keeps track of a search-in-progress; that can be simplified away. Its keyboard handler is new, see the next exercise below.

Threadview mode is new, and will use the draw-post-and-replies function you designed in Assignment 9a. It does not require any fancy keyboard handling, but rather just switches back to Viewall or Search mode (via "f1" or "f2"). Note that the Post it contains is an element of the History list; you shouldn’t try to delete that post from the history (so that it is still present when you switch back to the Viewall mode).

The Newitem mode allows for creating new posts and replies. Its keyboard handler should be mostly similar to your existing ones, in that it should handle backspace, return, "f1" and "f2", and single characters. On pressing enter, it should make a package that is either a "POST" or a "REPLY" ClientMsg, and switch back to Viewall mode.

Hint: focus on just one thing at a time – either one kind of handler at a time, or one kind of view at a time. In other words, either organize your process as "First, finish all of the to-draw handlers for these new views; second, finish all of the on-key handlers for these views," or "First, finish all the handlers of the Viewall view; second finish all the handlers of the Threadview view; third..." Don’t bounce back and forth between different handlers of different views, as that’s a very good way to get yourself confused.

Hint: the keyboard handling for the Viewall mode might not make sense until you begin the next stage below. Use dummy implementations (that simply leave the world unchanged) to stub out incomplete behaviors in your program, so you can test each part independently.

At this point, if you start your program in one of these four views, you should be able to see all posts, create a new post, view a thread (that you’ve created as an example), or search through incoming messages. Your Viewall view might not respond to key events particularly well yet, but the others should work.

Stage 6 – New user interaction: Posting versus Replying In Assignment 7a, the user can switch between the old EditviewPosts mode and SearchPosts mode, but has no way to distinguish entering a new post from replying to an existing one. To accomplish this, the user will need to enter commands in the Viewall mode instead of just typing in raw text:

; A Command is a string of the form
;  "catchup"
;  "new"
;  "reply ", followed by a number
;  "view ", followed by a number

A Command only matters when the user finishes typing into the Viewall mode and presses enter. Design a helper function process-command that takes the current Viewall world and responds to the command appropriately.

For example, the "new" command means "Create a new post". This should switch to Newitem mode, with the the parent ID# set fo #false.

Similarly, the "reply 123" command means "Create a reply to post 123", and should switch to Newitem mode with the parent id set fo 123.

A command of "view 456" should switch to the Threadview mode, focusing on the Post with id 456. (Your code should not crash if the id does not exist – what should it show instead?)

A command of "catchup" should simply send the "CATCHUP" ClientMsg to the server, to get back the full history of messages, clear the currently-being-edited command, and stay in the "Viewall" mode. Note: You will get a lot of "POST"s and "REPLY"s, very quickly, so only test this out after you’ve gotten your other views and helper functions working well!

Hint: Use string-split to break up the Command into a list of strings, and use string->number when needed to translate the digits into an actual number.

At this point, congratulations! You have a complete, working Piazza client!

As always, you are welcome to implement additional functionality should you desire to do so.