15 · A Play Is Only as Good as Its Script
What does the proof let me promise a customer?
Opening night has gone well. Puck can tell a customer which seats are free, reserve one, and release it. The manager pins up a new sign. “One ticket per customer.”
Start again with seats 3, 5, and 7 free. Viola books seat 3. The same Viola then asks to book seat 5, which is still free. Puck stamps both slips with exemplary care. The manager reads the name twice.
Bring with you. The booking contract and the difference between a proved promise and an expected result from a run.
The stamp is in perfect working order.
Read the promise at the counter
The reservation contract tells the clerk whether a particular seat was free when the request arrived. It also says that the requested seat is taken on return and that the other flags keep their entry values. Both seat requests fit this contract. When the box office reserves seat 3, the promise about the rest of the chart keeps seat 5 free for the second call.
Look at the two calls in the script. Each receives a chart and a seat number. Where does Viola's name appear? What fact could the second call use to decide whether this customer already holds a ticket?
Example 15-1 · Two tickets for Viola
Copy your whole example project. The main file makes both requests using the same reservation code as chapter 12. Prove and run the project.
Vada · Ada · Example 15-1
main.vadb · Link to this version
with Ada.Text_IO; use Ada.Text_IO;
with Seating; use Seating;
procedure Main is
Taken : Seat_Row :=
[True, True, False, True, False, True, False, True];
First, Second : Boolean;
begin
Reserve (Taken, 3, First);
pragma Assert (First);
Put_Line ("Viola reserved seat 3.");
Reserve (Taken, 5, Second);
pragma Assert (Second);
Put_Line ("Viola reserved seat 5.");
pragma Assert (Taken (2) and Taken (4));
end Main;
Varc · C-family · Example 15-1
main.va · Link to this version
import Ada.Text_IO; use Ada.Text_IO;
import Seating; use Seating;
fn Main() {
var taken: Seat_Row = [True, True, False, True, False, True, False, True];
var first, second: Boolean;
reserve(&taken, 3, &first);
assert first;
Put_Line("Viola reserved seat 3.");
reserve(&taken, 5, &second);
assert second;
Put_Line("Viola reserved seat 5.");
assert taken[2] && taken[4];
}
Vibe · Python · Example 15-1
main.vb · Link to this version
from seating import Seat_Row, reserve
def main() -> None:
taken = Seat_Row([True, True, False, True, False, True, False, True])
first: bool = reserve(taken, 3)
assert first
print("Viola reserved seat 3.")
second: bool = reserve(taken, 5)
assert second
print("Viola reserved seat 5.")
assert taken[2] and taken[4]
if __name__ == "__main__":
main()Syntax note. Vada and Varc receive each status in a writable argument. Vibe assigns the returned status. In each route, the customer name appears in the printed lines, and the chart stores occupancy flags.
Viola reserved seat 3.
Viola reserved seat 5.
The proof establishes both bookings under the stated seating contract. The run shows a case that violates the new sign. If Olivia made the second request instead, the booking function would see the same chart and seat number. The distinction the manager cares about needs to reach the program.
Put the new rule where Verada can check it
Suppose the manager means at most one active reservation per customer. Ask how the clerk will recognize a returning customer. A customer identifier can travel with the request, and the chart can record who holds each reservation. Now the second call can use the first booking to decide what to do.
Accept exactly when the seat is free and the customer holds no active reservation. On acceptance, record the customer at that seat and preserve every other seat's record. On refusal, preserve the whole chart. Cancellation frees the seat and clears its holder. Start with at most one seat per customer and prove that each operation preserves that rule.
When you implement the rule, try two tests. Start each with Viola in seat 3 and seat 5 free.
- Viola keeps seat 3. Her request for seat 5 is refused. Olivia can book seat 5.
- Viola cancels seat 3. Her next request for seat 5 succeeds.
Decide what the evidence covers
- A proved promise holds for calls that meet its conditions. A receipt agrees with the chart supplied to its lookup. The clerk still needs to supply the current chart.
- An example run gives the result for the requests in that script. The opening-night counts let us check four concrete results. The tally's proved bound covers every row.
- A new policy gives us a requirement to express. The proposed contract would cover every valid chart and request, including the two examples above.
Your cue
- Change the name in the second printed line from Viola to Olivia. Prove and run again. Which inputs to the two bookings change?
- Restore the script. Have Viola request seat 3 twice. Expect the second status to be false and adjust the last assertion to check that seat 3 is taken and seat 5 is free. Change the second message to
Viola: seat 3 already taken.Prove and run. Which rule explains that refusal? - On paper, choose one policy for the box office. Try one active reservation per customer or the group reservation from chapter 14. Write what the caller supplies, what the operation promises, and a short sequence that would expose a missing rule.
Prompter's notes
Changing the printed name leaves both booking calls the same. Changing the second seat to 3 makes the request arrive at a taken seat. The seat rule explains the refusal, whoever is asking.
For the one-ticket policy, pass a customer identifier with the seat number. When Viola's second request is refused, check that her booking stays in place and seat 5 stays free.
For the group policy, pass all three requested seats. On refusal, check the whole chart, including any free seat that came before the taken one.
The curtain is ready. The box office is ready. Puck has a new rule to put in the script. His cravat will require a separate amendment.
For the next production, the manuals take over. The Programmer Guide continues the course with projects, interfaces and larger programs, and the editor guide sets up proofs as you type.