;;;; A CGI demonstration program in Scheme with use of the LAML cgi library 
;;;; and HTML mirror libraries.
; ---------------------------------------------------------------------------
; Initial constants and functions

In scheme-source: Link from kn-laml-dir to it's cross reference table entry 3.1. The preamble part
(define kn-laml-dir "/user/normark/scheme/") In scheme-source: Link from laml-dir to it's cross reference table entry 3.1. The preamble part
(define laml-dir "/pack/laml/") In scheme-source: Link from source-directory to it's cross reference table entry 3.1. The preamble part
(define source-directory (string-append kn-laml-dir "tools/number-guess/")) In scheme-source: Link from number-guess-url-prefix to it's cross reference table entry 3.1. The preamble part
(define number-guess-url-prefix "http://www.cs.auc.dk/~normark/cgi-bin/number-guess/") ; Return an URL to a number guessing program with url parameters In scheme-source: Link from number-guess-url to it's cross reference table entry 3.1. The preamble part
(define (number-guess-url program-name par-name-list par-value-list) (string-append number-guess-url-prefix program-name "?" (make-url-parameters par-name-list par-value-list))) In scheme-source: Link from loading to it's cross reference table entry 3.1. The preamble part
; loading (load (string-append laml-dir "laml.scm")) ; Library Loading (lib-load "cgi.scm") ; A linked program source marker to section 3.1:
'The preamble part'
Mark char: a (lib-load "encode-decode.scm") ; A linked program source marker to section 3.1:
'The preamble part'
Mark char: b ; ; HTML mirror loading (lib-load "html4.0-loose/basis.scm") (lib-load "html4.0-loose/surface.scm") (lib-load "html4.0-loose/convenience.scm") ; Other loadings (lib-load "color.scm") (lib-load "time.scm") In scheme-source: Link from other-settings to it's cross reference table entry 3.1. The preamble part
; other-settings ; Setting testing conditions and access time In scheme-source: Link from cgi-testing to it's cross reference table entry 3.1. The preamble part
(define cgi-testing #f) In scheme-source: Link from cur-time to it's cross reference table entry 3.1. The preamble part
(define cur-time (current-time)) In scheme-source: Link from url-parameters to it's cross reference table entry 3.1. The preamble part
; url-parameters In scheme-source: Link from url-pars to it's cross reference table entry 3.1. The preamble part
(define url-pars (extract-url-parameters)) In scheme-source: Link from language-preference to it's cross reference table entry 3.1. The preamble part
(define language-preference (as-symbol (defaulted-get 'language url-pars 'english))) In scheme-source: Link from mode to it's cross reference table entry 3.1. The preamble part
(define mode (as-symbol (defaulted-get 'mode url-pars 'init))) ; ----------------------------------------------------------------------------- ; ; A common part of both the init and the play page In scheme-source: Link from guess-part to it's cross reference table entry 3.2. The init game part 3.3. The game part
(define (guess-part secret-number) (con (p) (text-choice "Dit gæt: " "Your guess: ") (horizontal-space 2) (text-line 'players-guess 3 "") ; A linked program source marker to section 3.2:
'The init game part'
Mark char: f (hidden-line 'secret-number (as-string secret-number)) ; A linked program source marker to section 3.2:
'The init game part'
Mark char: g (horizontal-space 6) (submit (text-choice "Gæt" "Guess")) ; A linked program source marker to section 3.2:
'The init game part'
Mark char: h )) ; The game init body In scheme-source: Link from game-init to it's cross reference table entry 3.2. The init game part
(define (game-init) (let ((secret-number (random 100))) ; A linked program source marker to section 3.2:
'The init game part'
Mark char: a (body (form-1 ; A linked program source marker to section 3.2:
'The init game part'
Mark char: b (number-guess-url "number-guess.cgi" (list 'language 'mode) (list language-preference "play")) (con (font-1 5 red (text-choice "Velkommen til 'Gæt et tal'" "Welcome to 'guess a number'")) (p) (hr) (p) (text-choice "Gæt et tal mellem 0 og 100" "Guess a number between 0 and 100") (guess-part secret-number) ; A linked program source marker to section 3.2:
'The init game part'
Mark char: c (p) (hr)))))) ; The play body In scheme-source: Link from game-play to it's cross reference table entry 3.3. The game part
(define (game-play) (let* ((form-a-list (map symbolize-key (extract-form-input))) ; A linked program source marker to section 3.3:
'The game part'
Mark char: i (secret-number (as-number (get 'secret-number form-a-list))) (players-guess (as-number (get 'players-guess form-a-list))) ) (body (form-1 ; A linked program source marker to section 3.3:
'The game part'
Mark char: j (number-guess-url "number-guess.cgi" (list 'language 'mode) (list language-preference "play")) (cond ; A linked program source marker to section 3.3:
'The game part'
Mark char: k ((> players-guess secret-number) (con (text-choice "Dit tal er for stort" "Your guess is too large") (guess-part secret-number) ; A linked program source marker to section 3.3:
'The game part'
Mark char: c )) ((< players-guess secret-number) (con (text-choice "Dit tal er for lille" "Your guess is too small") (guess-part secret-number))) ; A linked program source marker to section 3.3:
'The game part'
Mark char: d ((= players-guess secret-number) (con (font-color red (text-choice "Du ramte plet" "You got it")) (p) (a-tag ; A linked program source marker to section 3.3:
'The game part'
Mark char: e (number-guess-url "number-guess.cgi" (list 'language 'mode) (list language-preference "init")) (text-choice "Nyt spil" "New game"))))))))) In scheme-source: Link from page-write to it's cross reference table entry 2.1. The overall design 3.2. The init game part
; page-write (write-page (text-choice "Gæt et tal" "Guess a number") (cond ((eq? mode 'init) (game-init)) ; A linked program source marker to section 2.1:
'The overall design'
Mark char: b ((eq? mode 'play) (game-play)) ; A linked program source marker to section 2.1:
'The overall design'
Mark char: a (else (game-error))) white black blue blue) (end)