This lab looks at the Orbitz web program bug (from Tuesday's class) and general issues with programming with state on the web.
As a reminder (or for those who missed class on Tuesday), here are the steps that showed the bug:
Download the starter file for lab. In it, you'll find data definitions, an example database of hotel data, and some printing routines for displaying hotel data. You'll also find several text-gui versions of an Orbitz mockup, which we'll use in the following exercises.
Some of the exercises ask you to explain your answers. Take this part seriously and write your reasons down in your solutions file for lab (just put the answers in a block comment). Being able to give technical arguments precisely is one of the skills this lab tries to practice, and we will read your answers.
Version 1 follows the set!-free style we've used in class all term. Run that version to familiarize yourself with the prompts and interface. When the program prompts you for which hotel to view, just enter the number labeling the hotel. Use any single number for a date when you reserve a hotel.
In a fit of withdrawal from assignment statements, Billie Lovesbitz rewrites version 1 as version 2 (resulting in some hideously ugly Scheme code, but we'll ignore that for now). Run version 2 and either produce an interaction (sequence of inputs to the function) that gives a different result than the same inputs to version 1 or justify (in writing) that no such input sequence exists.
Billie decides to release version 2 as a web program, which requires breaking the code into functions for different scripts and adding "submit" functions, as we did in class. Study the result (version 3) and run it. Can you reproduce the Orbitz bug? Either give a sequence of steps to do it or try to explain (in writing) why the Orbitz bug can't show up with this code.
Version 3 doesn't really simulate the Orbitz scenario because there the user switched between pages in different windows, and version 3 doesn't give a way to do that. We can simulate different pages in different windows by modifying the scripts (resulting in version 4) to return the pages (functions) rather than calling them automatically. We can simulate pressing the submit buttons by giving names to the results of calling each page, then calling these functions/pages in turn. For example:
(define mp (hotel-main-page4)) (define choosehilton (mp 1)) ...
Reproduce the Orbitz bug in version 4 by writing down a sequence of Scheme expressions that reveal the bug. What features of version 4 made the bug possible?
Copy version 1 (the set!-free original) to create version 5 that has scripts with multiple pages accessible (similar in spirit to version 4) but without set!. Test version 5 to make sure it produces similar interactions to version 1. Can you reproduce the bug from version 4 in version 5? Either show steps that yield the bug or explain why the bug doesn't occur with version 5.
In your edits, be sure to rename the recursive call to main-hotel-page1 in the inner cond where reserve-for equals no.
(printf "~a~n" thelist)is fine). Don't worry about letting the user delete reservations or about resetting the list contents with each new execution from interactions window (though it's fine to reset if you wish). Both of these issues are besides the point of this exercise.
Everybody should be able to finish up to this point
Convert a copy of version 6 to work as web scripts with multiple active windows (as with version 4).
Ideally (from a utility perspective), all pages should see reservations made in all other pages. For example, if a user has windows open to view each of hotel1 and hotel2, and makes a reservation in the hotel1 page, the "main page" reached from the hotel2 page should show the hotel1 reservation. Does your version have this behavior? Either write the sequence demonstrating this or explain why it does not.
If your version does not have this behavior (and you have time), try making another version that does have this behavior. If you are short on time, do to the next question first
What lessons can you draw about web programming and state (meaning variables and set!) from these exercises?