Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.1|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;;Model
6 ;build-number : (listof number) -> number
7 ;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents.
9 ;x10add : number number -> number
10 ;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add).
12 (define (build-number alon)
13 (local ((define (x10add n1 n2)
14 (+ (* n2 10) n1)))
15 (foldl x10add 0 alon)))
17 ;;View
19 (define a-msg (make-message "Please choose 3 digits"))
21 ;;DIGITS is a list of gui-items [choice]
22 (define DIGITS (local ((define (create-choice-gui colnum)
23 (make-choice (build-list 10 number->string))))
24 (build-list 3 create-choice-gui)))
26 ;;list-of-digit-choices : number -> gui-item [choice]
29 ;;Controller
31 (define (submit-digits event)
32 (draw-message a-msg (number->string (build-number (map choice-index DIGITS)))))
34 (create-window (list DIGITS
35 (list a-msg)
36 (list (make-button "Submit digits" submit-digits))))