7.1.0.8

3 — Exploring Your Favorite Programming Language Some More

Due Monday, September 17, midnight

Delivery You must deliver five artifacts in a directory called 3:
  • 3, the artifact for task 1;

  • server-for-given-2spread.PP, which is the artifact for task 2;

    PP is a language-specific suffix.

    If your chosen language demands capitalized file names, as Haskell does, you may name this artifact Seever-for-given-2spread.pdf Server-for-given-2spread.PP.

  • client, an executable that exercises the spread component you received (task 3);

  • tests, a folder with one test case for client, part of task 3;

  • server-spread.pdf or server-spread.md, the artifact for task 4.

All auxiliary files must be put into a sub-directory called Aux.

If you are coding on a Windows 10 computer, you may name this directory Auxiliary.

Task 1 Since your eventual product will consist of a server and remote clients, your manager wishes to understand how well your chosen language deals with TCP connections. Develop a TCP server program that allows clients to connect on port 8000. A client sends over JSON values. The server reads all those JSON values from the TCP input stream until the stream is closed. At that point, the server sends all the JSON values back to the TCP output stream, each on a separated line, embedded in a JSON array that indicates its reverse position in the stream (counting down to 0).

The idea form of reuse is simply importing the code without modification.

Clearly, this server is just a wrapper around the solution of task 2 of 2 — Exploring Your Favorite Programming Language. Reuse your code. Improve as needed.

Task 2 Surprise! You live in Codemanistan and your team manager has deposited a given-2spread.pdf from some other team in your repo’s directory 3. Implement the specification.

If the given specification does not articulate what is to be computed in certain situations, you may implement whatever is convenient. If the specification requests capabilities that are unnecessary to implement client (see below), you do not have to implement them. A request for a graphical interface is a good example; it is both unnecessary and demonstrates that the specifiers failed to understand the difference between the meaning of a spreadsheet (aka model) and its graphical rendering (aka view)

Task 3 Also Implement client, an executable that relies on your own specification (2spread.pdf) to build and query spreadsheets. Once you get your requested implementation back, you can link it to the client to obtain a complete program. As announced in class, you will work on the linking in class on Tuesday.

The client must read JSON values from STDIN and print answers to STDOUT. Roughly speaking, a user of the interactive harness can request the creation of a spreadsheet, give a name to a spreadsheet, place a new formula into a cell of a specific spreadsheet, and ask for the value of a cell.

Here are the well-formed JSON values it must deal with::
  • named spreadsheet

    ["sheet", name:string, [[JF, ...] ...]]

    The command is valid if the "array" in the third position forms a rectangle of JFs and all ">" formulas point to a valid cell in this rectangle.

    A valid named-spreadsheet command creates a spreadsheet and gives it the specified name. Other commands can refer to the spreadsheet via this name. It produces no output.

  • set request

    ["set" , name:string, x:N, y:N, JF]

    The command is valid if the named spreadsheet has a cell at (x,y) and all ">" formulas in JF point to a valid cell in the named spreadsheet.

    A valid set-request command replaces the formula in cell (x,y) with the given one. It produces no output.

  • at request

    ["at", name:string, x:N, y:N]

    The command is valid if the named spreadsheet has a cell at (x,y).

    A valid at command determines the value of the cell (x,y) in the named spreadsheet and prints it to STDOUT. If the evaluation of the formula discovers a circularity (self-reference) in the spreadsheet, the client must write false.

All non-well-formed JSON values are discarded. If a user enters a non-JSON string, the program may crash.

You must make a decision whether (or how much) client can check the validity of well-formed JSON expressions without re-implementing the spreadsheet functionality yourself. For cases when it can’t, it must collaborate with the server—but you need to rely on our own specification to make this decision.

The well-formed JSON format for Formulas is as follows:

    JF is one of:

    -- number

    -- [">", N, N]

    -- [JF , "+", JF]

    -- [JF , "*", JF]

N is a (natural) number (0, 1, 2, ...). This implies that cells are referenced with coordinates starting at 0. Following computer graphics, the x axis goes from left to right and the y axis from top to bottom.

Create the folder tests with two files: 1-in.json and 1-out.json. The former specifies a series of JSON values that are inputs for the client; the latter specify the expected outputs.

Task 4 Your company has decided to build a spreadsheet "micro service"If you are unfamiliar with this term, google it. The knowledge may come in handy if you interview with Amazon. so that it can commercialize it as spread.com. They have put you in charge of adding a complete protocol specification for the server, that is, a description of how clients connect to the server (ordering of messages, shape of messages).

You may assume that your subs in Codemanistan will wrap their amazing client program with a TCP-based server.