7.1.2 Defining an Accept for a Structure With Several Fields

The following code shows how to define an
accept
for a structure (instance) with several fields. That
accept
is then used within another similar
accept
call.

A presentation type called
ticket
is defined. The
accept
method has two recursive calls to
accept
, one to read the name of a candidate for president and another to read the name of the running mate. We provide two possible
accept
methods; in order to compare them, you will have to compile first one and then the other. The first reads the two names separated by a comma on the same line. The second reads the two names on separate lines, delimited by
RETURN
. They both do completion within the field. That is, if you do
(accept 'ticket :stream win)
with the first
accept
method, and type
"Bu,Qu<RETURN>
", the screen appearance will be
"Bush,Quayle"
and the return value will be
(BUSH QUAYLE)
.

If you use the second
accept
method and type:

"Cl

Go

"

the window will contain:

"Clinton

Gore"

and the return value will be
(CLINTON GORE)
.

This example also demonstrates simple cross-field constraints by insisting that the two candidates be of the same party.