In this chapter we give an example of a CGI program written in Scheme using the LAML cgi library.
The name of the file must be number-guess.cgi , and it should be file protected to be executable (typically with chmod 755 ). This starts MzScheme via a shell script, and the load line is executed. It would be perfectly possible to place the entire Scheme program here, but we prefer in general to organize our software in a directory outside the .public_html catalogue. Therefore we load the number guessing program from the tutorial example directory in my LAML development directory, which happens to be /normark/scheme . As another important point, we decide to organize the number guessing system as a single program, which in the page-write part branches between a game init part (#!/bin/sh string=? ; exec /pack/mzscheme/bin/mzscheme \-r \$0 "\$\@" ;; This program implements a number guessing game, ;; which is commonly used to illustrate simple WWW ;; server programming. (define example-tutorial-dir "/user/normark/scheme/examples/tutorial/") (load (string-append example-tutorial-dir "cgi-programming/number-guess.scm"))
This ends the game preamble part.((language . "english") (mode . "init"))
((secret-number . "42") (players-guess . "22"))We prepare a body with a new form element (as above) (