Assignment 9
Consider the following Scheme function:
(define ladd
(lambda ()
(let ((more? (read)))
(if more?
(+ (read) (ladd))
0))))
which repeatedly asks for more numbers and then sums all the
numbers. For example,
> (load "ladd.ss")
> (ladd)
#t
10
#t
20
#t
30
#t
40
#f
100
You are to write a web server application which implements the above
function by taking its input from web forms and producing its output
as HTML pages. Your application should be robust: it should work in
the presence of crazy control actions by the user (cloning windows,
bookmarking intermediate pages, using the back button, submitting forms
more than once, etc).
You will need to download and install the tomcat server. See http://jakarta.apache.org/tomcat/
for details. The easiest way I found to work with the server is to put
the Java files under webapps/examples/WEB-INF/classes
.
You will probably need some guidance with this. I will try to go
through the details in lectures. Meanwhile you can test my
implementation by going to
http://dogfish.cs.indiana.edu:8080/examples/c311.html. Please let
me know if you encounter any problems!
Turn in a URL to sabry@cs.indiana.edu.
Clarification
In this particular example, the continuation
can be represented as the sum of numbers seen so far. Taking advantage
of this can greatly simplify the code but misses the point of the
assignment, which is to explore a general technique that should work
in other situations. For example, consider a slightly modified version
of our assignment in which the operation to perform on the number is
not hardwired to be "addition". Instead after the user enters all the
numbers, the user then supplies an operation to apply which could be
addition, multiplication, or even a Java method. It is clear that the
code now must maintain the entire list of numbers that has been
entered: doing so in the URL is not practical, and using hidden
parameters is not much better. Furthermore the information saved at
every point might be much more complex than simple numbers. Converting
the code to CPS and using the general technique explained in the paper
addresses all these issues in general. If you can still find another
way to solve the problem in its full generality as explained above,
I'd love to see your solution.