52
CHAPTER 4. SCHEME SERVLETS
Exercise 4 Modify the date.servlet example above to include more sophisticated
HTML and CSS, then visit the page and hit the refresh button several times. You
should notice that the time changes each time you hit the refresh button.
Exercise 5 Write a servlet that displays a random number using
[(Math.random)]
This scheme expression generates a random decimal number between 0.0 and
1.0. If you want a whole number between say 0 and 100, then you can use the
following expression instead:
[(round (* 100 (Math.random)))]
By multiplying the random number by 100, we get a decimal number between 0.0
and 100.0. The round operator then rounds that number to the nearest whole
number in the range 0 to 100.
Exercise 6 What is the result of evaluating the following Scheme expressions:
{ 3 + 4 = [(+ 3 4)] }
{ [(* 3 3)]   [(+ 2 5)] = [(/ 4 2)] }
{ A day contains [(* 24 60 60)] seconds!}
As mentioned above, the curly braces in a servlet {} indicate that the en 
closed text is to be sent verbatim to the client, except that text enclosed in
square braces
is first evaluated to get some  interesting  value which is then inserted into the
text. This curly brace/square brace notation is called quasi string notation. It
is another example of a Scheme expression.
4.5
Quasi strings and string append
The general form of a quasi string expression is as follows:
{...text...[A].....
...text...[B].....
....
...text...[C].....}
The rule for evaluating such an expression is to first evaluate the embedded
Scheme expressions A, B, ..., C, and then to insert the values one obtains in the
corresponding places in the string. There is a Scheme function string append
which can be used to achieve a similar effect, e.g. instead of writing:
{the sum of 5 and 7 is [(+ 5 7)] the difference is [(  5 7)]}
one could write




Php Web Hosting Introduction to Interactive Web Design Php Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.