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" (-
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/06/2008 for the course CS 536 taught by Professor Fisler during the Fall '07 term at WPI.

Page1 / 2

The conversion exercises from class - ; The define-script...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online