; Note: you need to be in "Intermediate Student with Lambda" or "Advanced Student" language, ; and you need the "gui.ss" teachpack loaded. ; can-vote? : number => boolean (define (can-vote? age) (>= age 18)) "Examples of can-vote?:" (can-vote? 17) "should be false" (can-vote? 18) "should be true" (can-vote? 97) "should be true" ; voting-message : string => string (define (voting-message text) (local [(define age (string->number text))] (cond [(not (number? age)) (format "I don't understand ~s; the age must be a number." text)] [(>= age 18) (format "~s is old enough to vote. Congratulations!" age)] [(< age 18) (format "~s is NOT old enough to vote yet." age)]))) "Examples of voting-message:" (voting-message "18") "should be \"18 is old enough to vote. Congratulations!\"" (voting-message "17") "should be \"17 is NOT old enough to vote.\"" (voting-message "p3n890") "should be \"I don't understand \"p3n890\"; the age must be a number.\"" (define age-box (make-text "How old are you?")) (define ANSWER-LENGTH 90) (define answer (make-message (make-string ANSWER-LENGTH #\space))) (define do-it-button (make-button "Go ahead!" (lambda (event) (draw-message answer (voting-message (text-contents age-box)))))) (define quit-button (make-button "Quit" hide-window)) ; hello: dummy -> nothing ; Puts up a window. Whenever the "Go ahead" button is clicked, checks the ; contents of the age-box, and puts an appropriate message in "answer". (define (hello dummy) (create-window (list (list age-box do-it-button) (list answer) (list quit-button))))