10.02 script-pos-full

10.02 script-pos-full - (define (clean-adder) (printf...

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

View Full Document Right Arrow Icon
;; CS 1102: Starter file for lecture on script conversion ;;;; 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))) ;;;;; 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))]))) ;;;;;;;; the adder (a bit cleaner) ;;;;;;;;;;;;;;;;;;;;;;;;
Background image of page 1

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

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

Unformatted text preview: (define (clean-adder) (printf "sum: ~a~n" (+ (web-read "First number") (web-read "Second number")))) ;;;;;;;; the tip calculator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; helper function (define (add-tip bill) (+ bill (* bill (/ (web-read "Enter tip percentage") 100)))) ; the main function (define (tip-adder) (add-tip (web-read "Enter bill amount"))) ;;;;;;;; tallying charges ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (tally item-list) (cond [(empty? item-list) 0] [else (+ (web-read (format "Enter cost for ~a" (first item-list))) (tally (rest item-list)))])) ;;;;;;; tracking accounts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define account (let ([balance 0]) (lambda () (begin (set! balance (+ balance (web-read (format "Balance: ~a; Change by" balance)))) (account)))))...
View Full Document

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

Page1 / 2

10.02 script-pos-full - (define (clean-adder) (printf...

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