{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

The conversion exercises from class

How to Design Programs: An Introduction to Programming and Computing

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;;;; The define-script macro ;;;;;;;;;;;;;;;;;;;;;;;; (define abort #f) (let/cc grab-abort (set! abort grab-abort)) (define-syntax define-script (syntax-rules () [(define-script (script-name arg ...) body) (define (script-name arg ...) (abort body))])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; a common "web form" with a single input (define (web-read promptstr) (begin (printf (format "~a: " promptstr)) (read))) (define-script (web-read/k promptstr action) (begin (printf (format "~a: " promptstr)) (action (read)))) ;;;;; the age/vote program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; age-page-nonweb : -> void ;; displays ability to vote based on user's age (define (age-page-nonweb) (let [(age (web-read "Enter your age"))] (cond [(>= age 18) (printf "Don't forget to vote!")] [else (printf "You'll be able to vote in ~a years" (- 18 age))]))) (define-script (age-page/web) (web-read/k "Enter your age" (lambda (hole) (let [(age hole)] (cond [(>= age 18) (printf "Don't forget to vote!")] [else (printf "You'll be able to vote in ~a years" (- 18 age))]))))) ;;;;;;;; the adder (a bit cleaner) ;;;;;;;;;;;;;;;;;;;;;;;; (define (clean-adder) (printf "sum: ~a~n" (+ (web-read "First number")
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}