Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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")))))
4 12687dd9 2023-08-04 jrmu ;;Model
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;build-number : (listof number) -> number
7 12687dd9 2023-08-04 jrmu ;Given alon which represent the digits of a number, with the first digit representing the most significant digit, return the number alon represents.
8 12687dd9 2023-08-04 jrmu
9 12687dd9 2023-08-04 jrmu ;x10add : number number -> number
10 12687dd9 2023-08-04 jrmu ;Given n1 and n2, multiply n2 by 10 (ie, x10) then add to n1 (ie, add).
11 12687dd9 2023-08-04 jrmu
12 12687dd9 2023-08-04 jrmu (define (build-number alon)
13 12687dd9 2023-08-04 jrmu (local ((define (x10add n1 n2)
14 12687dd9 2023-08-04 jrmu (+ (* n2 10) n1)))
15 12687dd9 2023-08-04 jrmu (foldl x10add 0 alon)))
16 12687dd9 2023-08-04 jrmu
17 12687dd9 2023-08-04 jrmu ;;View
18 12687dd9 2023-08-04 jrmu
19 12687dd9 2023-08-04 jrmu (define a-msg (make-message "Please choose 3 digits"))
20 12687dd9 2023-08-04 jrmu
21 12687dd9 2023-08-04 jrmu ;;DIGITS is a list of gui-items [choice]
22 12687dd9 2023-08-04 jrmu (define DIGITS (local ((define (create-choice-gui colnum)
23 12687dd9 2023-08-04 jrmu (make-choice (build-list 10 number->string))))
24 12687dd9 2023-08-04 jrmu (build-list 3 create-choice-gui)))
25 12687dd9 2023-08-04 jrmu
26 12687dd9 2023-08-04 jrmu ;;list-of-digit-choices : number -> gui-item [choice]
27 12687dd9 2023-08-04 jrmu
28 12687dd9 2023-08-04 jrmu
29 12687dd9 2023-08-04 jrmu ;;Controller
30 12687dd9 2023-08-04 jrmu
31 12687dd9 2023-08-04 jrmu (define (submit-digits event)
32 12687dd9 2023-08-04 jrmu (draw-message a-msg (number->string (build-number (map choice-index DIGITS)))))
33 12687dd9 2023-08-04 jrmu
34 12687dd9 2023-08-04 jrmu (create-window (list DIGITS
35 12687dd9 2023-08-04 jrmu (list a-msg)
36 12687dd9 2023-08-04 jrmu (list (make-button "Submit digits" submit-digits))))