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-advanced-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
8 ;;queue : (listof strings)
9 ;;Lists all the tasks which need to be done.
14 ;;The current index of the queue.
16 (define queue-index 0)
18 ;enter : string -> void
19 ;Adds atask to the end of queue.
22 (set! queue (append queue
26 ;Returns the next task in the queue based on queue-index. If the end of the queue is reached, return the current task in the queue specified by queue-index. If the queue is empty, return 'NoneLeft.
30 [(empty? queue) 'NoneLeft]
31 [(= (length queue) (add1 queue-index)) (list-ref queue queue-index)]
32 [else (begin (set! queue-index (add1 queue-index))
33 (list-ref queue queue-index))]))
36 ;Removes the first task in the queue. If there are no tasks left to be removed, do nothing.
40 [(empty? queue) (void)]
41 [else (set! queue (rest queue))]))
44 ;Counts the number of items in the queue.
51 ;;GUI-items, text and messages
52 (define task-message (make-message "Welcome to the Task Manager"))
53 (define task-number-message (make-message "2000"))
54 (define input-text (make-text "Task: "))
58 (define (enter-callback event)
60 [(equal? (text-contents input-text) "") true]
61 [else (begin (enter (text-contents input-text))
64 [(= (length queue) 1) (draw-first-task)]
67 ;;draw-queue-number : -> true
68 ;;Draws the queue number and returns true.
69 (define (draw-queue-number)
70 (draw-message task-number-message (number->string (length queue))))
72 ;draw-first-task : -> true
73 ;Draws the first task in the queue and returns true.
74 (define (draw-first-task)
75 (draw-message task-message (first queue)))
77 (define (next-callback event)
79 [(>= (length queue) 2)
87 (draw-message task-message "No more tasks left!"))]
88 [(= (length queue) 0) true]))
90 (define (quit-callback event)
91 (hide-window task-manager-win))
93 (define enter-button (make-button "Enter" enter-callback))
94 (define next-button (make-button "Next" next-callback))
95 (define quit-button (make-button "Quit" quit-callback))
97 (define task-manager-win
98 (create-window (list (list task-message task-number-message)
99 (list input-text enter-button)
100 (list next-button quit-button))))
108 (and (equal? (list "hi" "joe" "it's" "me") queue)
110 (equal? (next) "it's")
113 (equal? queue (list "joe" "it's" "me"))))))
118 ;;Initialize queue, queue-index