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

Show source file in large font In scheme-source: Link from kn-laml-dir to it's cross reference table entry 
(define kn-laml-dir "/user/normark/scheme/") Show source file in large font In scheme-source: Link from laml-dir to it's cross reference table entry 
(define laml-dir "/pack/laml/") Show source file in large font In scheme-source: Link from source-directory to it's cross reference table entry 
(define source-directory (string-append kn-laml-dir "tools/number-guess/")) Show source file in large font In scheme-source: Link from number-guess-url-prefix to it's cross reference table entry 
(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 Show source file in large font In scheme-source: Link from number-guess-url to it's cross reference table entry 
(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))) Show source file in large font In scheme-source: Link from loading to it's cross reference table entry 
; loading (load (string-append laml-dir "laml.scm")) ; Library Loading (lib-load "cgi.scm") ; A program source marker WITHOUT a link to the documentation (lib-load "encode-decode.scm") ; A program source marker WITHOUT a link to the documentation ; ; 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") Show source file in large font In scheme-source: Link from other-settings to it's cross reference table entry 
; other-settings ; Setting testing conditions and access time Show source file in large font In scheme-source: Link from cgi-testing to it's cross reference table entry 
(define cgi-testing #f) Show source file in large font In scheme-source: Link from cur-time to it's cross reference table entry 
(define cur-time (current-time)) Show source file in large font In scheme-source: Link from url-parameters to it's cross reference table entry 
; url-parameters Show source file in large font In scheme-source: Link from url-pars to it's cross reference table entry 
(define url-pars (extract-url-parameters)) Show source file in large font In scheme-source: Link from language-preference to it's cross reference table entry 
(define language-preference (as-symbol (defaulted-get 'language url-pars 'english))) Show source file in large font In scheme-source: Link from mode to it's cross reference table entry 
(define mode (as-symbol (defaulted-get 'mode url-pars 'init))) ; ----------------------------------------------------------------------------- ; ; A common part of both the init and the play page Show source file in large font In scheme-source: Link from guess-part to it's cross reference table entry 
(define (guess-part secret-number) (con (p) (text-choice "Dit gæt: " "Your guess: ") (horizontal-space 2) (text-line 'players-guess 3 "") ; A program source marker WITHOUT a link to the documentation (hidden-line 'secret-number (as-string secret-number)) ; A program source marker WITHOUT a link to the documentation (horizontal-space 6) (submit (text-choice "Gæt" "Guess")) ; A program source marker WITHOUT a link to the documentation )) ; The game init body Show source file in large font In scheme-source: Link from game-init to it's cross reference table entry 
(define (game-init) (let ((secret-number (random 100))) ; A program source marker WITHOUT a link to the documentation (body (form-1 ; A program source marker WITHOUT a link to the documentation (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 program source marker WITHOUT a link to the documentation (p) (hr)))))) ; The play body Show source file in large font In scheme-source: Link from game-play to it's cross reference table entry 
(define (game-play) (let* ((form-a-list (map symbolize-key (extract-form-input))) ; A program source marker WITHOUT a link to the documentation (secret-number (as-number (get 'secret-number form-a-list))) (players-guess (as-number (get 'players-guess form-a-list))) ) (body (form-1 ; A program source marker WITHOUT a link to the documentation (number-guess-url "number-guess.cgi" (list 'language 'mode) (list language-preference "play")) (cond ; A program source marker WITHOUT a link to the documentation ((> players-guess secret-number) (con (text-choice "Dit tal er for stort" "Your guess is too large") (guess-part secret-number) ; A program source marker WITHOUT a link to the documentation )) ((< players-guess secret-number) (con (text-choice "Dit tal er for lille" "Your guess is too small") (guess-part secret-number))) ; A program source marker WITHOUT a link to the documentation ((= players-guess secret-number) (con (font-color red (text-choice "Du ramte plet" "You got it")) (p) (a-tag ; A program source marker WITHOUT a link to the documentation (number-guess-url "number-guess.cgi" (list 'language 'mode) (list language-preference "init")) (text-choice "Nyt spil" "New game"))))))))) Show source file in large font In scheme-source: Link from page-write to it's cross reference table entry 
; page-write (write-page (text-choice "Gæt et tal" "Guess a number") (cond ((eq? mode 'init) (game-init)) ; A program source marker WITHOUT a link to the documentation ((eq? mode 'play) (game-play)) ; A program source marker WITHOUT a link to the documentation (else (game-error))) white black blue blue) (end)