Fundamentals of CS I (CS151 2002F)
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
Summary:
In this laboratory, you will explore that random
procedure using some fun
Web services.
a. Make a copy of
dicegame.ss
b. Make the corresponding CGI script.
#!/bin/bash /home/rebelsky/bin/schemeweb dicegame.ss
c. Share the CGI script and make it executable.
% share dicegame.ss % share dicegame.cgi % chmod a+x dicegame.cgi
d. Start DrScheme
Verify that the dicegame.cgi script works.
Sarah and Steven Schemer are somewhat stymied by the use of a
helper procedure for game-page. They'd like to replace that
pair of procedures with
(define game-page
(lambda (account)
(let ((new-account (+ account (if (odd? (pair-a-dice)) 1 -1))))
(make-page
(head "A Dice Game")
(body
(string-append
(heading 1 (if (odd? (pair-a-dice)) "You Win!" "I Win!"))
(string #\newline)
(paragraph
(string-append "The roll was " (number->string (pair-a-dice))))
(string #\newline)
(paragraph
(string-append "You now have $"
(number->string new-account)))
(string #\newline)
(form "dicegame.cgi" "Roll!"
(hidden "account"
(number->string new-account)))
) ; string-append
) ; body
) ; make-page
) ; let
) ; lambda
) ; define game-page
a. What do you think about their idea?
Note that you might test the effects of this modified procedure
from within DrScheme. It might be helpful to add a line to
pair-a-dice that uses display to
indicate that the procedure has been called.
(define pair-a-dice
(lambda ()
(display "Rolling dice ...")
(+ (roll-a-die) (roll-a-die))))
Note that you should remove the display before running
your script through the Web.
b. I originally wrote this problem before you learned let.
Use let to rewrite game-page without a helper
procedure.
Update dicegame.ss so that the player wins if the
two dice total 7 or 11 rather than an odd number.
Update dicegame.ss so that the player wins if the
two dice total 7 or 11 or if both dice have the same value.
Update dicegame.ss so that the player can choose
the amount to bet.
Thursday, 19 September 2002 [Samuel A. Rebelsky]
Friday, 20 September 2002 [Samuel A. Rebelsky]
Monday, 4 November 2002 [Samuel A. Rebelsky]
game-page.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Nov 4 08:29:18 2002.
The source to the document was last modified on Mon Nov 4 08:29:11 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/random.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby