2 — Exploring Your Favorite Programming Language
Due Thursday, September 13, midnight
spread.pdf, the artifact for task 1.
2, the executable for task 2, and
Task 1 Your company has hired a group of stellar programmers in Codemanistan, a country located in a galaxy far, far away. Your manager has put you in charge of writing a specification for the interface for a module, dubbed spreadsheet, which these stellar programmers will implement in your favorite language and ship back real soon.
building a spreadsheet from a rectangular arrangement of formulas
determining the value of a position (cell) in such a rectangle
placing a formula into a specific position
Formulate your specification in a mix of English and technical terms appropriate for your chosen language. For example, in Java you’d use the term package while a Racketeer would speak of modules.
Write a specification in memo form. It must fit on a single page in a 12-point PDF document. In "from" use your manager’s name, in "to" say "Matthias^2" or "Jason^2".
Specify the precise language (name, version) in which you expect the product to be written in.
Task 2 Your company has chosen JSON as the data language for your project. (Well, your team voted, and the vast majority fell for the latest and greatest teenage-heartbreak data fashion.)
So, it is time to explore your chosen language with small programs that confirm your memo’s claims.
Develop a program that echos JSON values on the Linux command line. Specifically, the program reads an unlimited number of JSON values from STDIN until the input stream is closed (^D). At that point, the program prints all the JSON values, each on a separated line, embedded in a JSON array that indicates its reverse position in the stream (counting down to 0).
[login-students: matthias] $ ./2 |
[1,2] |
{"a":1} |
^D |
[1,[1,2]] |
[0,{"a":1}] |
[login-students: matthias] $ |
You are not guaranteed that every JSON value occupies a single line.
Note Instead of typing JSON values into the program by hand, you may wish to use the re-direction facility of Unix/Linux:
[login-students: matthias] $ cat sample-input |
[1,2] |
{"a":1} |
[login-students: matthias] $ cat expected-output |
[1,[1,2]] |
[0,{"a":1}] |
[login-students: matthias] $ ./2 < sample-input > sample-output |
[login-students: matthias] $ diff sample-output expected-output |
[login-students: matthias] $ |
If diff does not display any lines, your test succeeded.If you recognize a generalization of the test idea from Fundamentals I, then you are on the right track. Alternatively, you can run
[login-students: matthias] $ ./2 < sample-input | diff - expected-output |
which uses Unix pipes to send the actual output into diff as the first input and compares it with the expected output directly.