70
CHAPTER 5. EXAMPLES OF SCHEME SERVLETS
{
table demo
text align:center">
Office hours
style="background:white">
[(trs "" '(
( time
mon
tue
wed
thu
fri
sat
sun)
( 9
th
th
)
(10
aj
)
(11
aj
)
(12
aj
)
( 1
ef
ef )
( 2
ef
ef )
( 3
)
( 4
rs
rs
rs
)
))]
}
Figure 5.4: A simple table servlet
5.4
Scheme Tables and Lists
Next we give an example of using Scheme to create HTML tables. This will
turn out to be quite useful when we are working with databases, as the answer
to a database query often takes the form of a table. Figure 5.4 gives an exam
ple of creating an HTML table from a list using the trs procedurfe from the
tables.scm library (which we assume has been preloaded by the server).
The new Scheme idea we need to use here is the notion of a list which is
represented in Scheme by placing a single quote (') in front of an S expression.
The effect is for Scheme to treat the S expression as data and, in particular,
not to try to evaluate it.
One of the most powerful features of Scheme is that it allows you to work
in this way with lists of data in a relatively simple way. You can create a list of
the weekdays by putting a single quote in front of a parenthesized sequence of
symbols:
'(mon tue wed thu fri)
The single quote indicates to the Scheme interpreter that the following term is
just data and should not be evaluated. For example,
(+ 1 2 3)
evaluates to 6, but
Php Web Hosting Introduction to Interactive Web Design Php Hosting
|
|
|
|
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved. |