;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-reader.ss" "lang")((modname |22.3|) (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"))))) ;;Model ;build-number : (listof number) -> number ;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents. ;x10add : number number -> number ;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add). (define (build-number alon) (local ((define (x10add n1 n2) (+ (* n2 10) n1))) (foldl x10add 0 alon))) ;;View (define a-msg (make-message "Please choose 3 digits")) ;;DIGITS is a list of gui-items [choice] (define DIGITS (local ((define (create-choice-gui colnum) (make-choice (build-list 10 number->string)))) (build-list 3 create-choice-gui))) ;;list-of-digit-choices : number -> gui-item [choice] ;;Controller (define (submit-digits event) (draw-message a-msg (number->string (build-number (map choice-index DIGITS))))) (create-window (list DIGITS (list a-msg) (list (make-button "Submit digits" submit-digits))))