For a trivial example of using a function to generate dynamic content, let’s write a function that generates a page with a different random number each time it’s requested.
As this function shows, you can just use **FORMAT**
to print HTML to the stream returned by request-reply-stream
. In the next section, I’ll show you more convenient ways to programmatically generate HTML.9
As it does in the publish-file
function, the :path
argument specifies the path part of the URL that will result in this function being invoked. The :function
argument specifies either the name or an actual function object. Using the name of a function, as shown here, allows you to redefine the function later without republishing and have AllegroServe use the new function definition. After evaluating the call to publish
, you can point your browser at to get a page with a random number on it, as shown in Figure 26-3.
Figure 26-3. http://localhost:2001/random-number