[plt-scheme] Re: HTDP Exercise 22.3.3. - Hint needed
Hi Matt,
I'm not a 100% whether or not this is what you (plural) had in mind,
well it does work.
I've used the functions returning functions in this case, however it
seems a bit odd, I mean yes it works, but doesn't this produce more
overhead compared to using a generalized function with parameters instead?
Guenther
;;model
(define pad
'((1 2 3)
(4 5 6)
(7 8 9)
(\# 0 *)))
(define pad2
'((1 2 3 +)
(4 5 6 -)
(7 8 9 *)
(0 = \. /)))
;; view
(define md (make-message "n"))
(define (pad->gui title a-list)
(cons
(list (make-message title))
(cons (list md)
(traverse a-list))))
(define (traverse a-list)
(cond
((empty? a-list) empty)
((list? a-list)
(cons (traverse (first a-list))
(traverse (rest a-list))))
(else
(make-button
(cond
((symbol? a-list) (symbol->string a-list))
(else (number->string a-list)))
(fun-composer a-list)))))
;; controller
(define (fun-composer a-string)
(local
((define (cb e)
(draw-message md (cond
((symbol? a-string)(symbol->string a-string))
(else (number->string a-string))))))
cb))
(create-window (pad->gui "PHONE" pad))
Guenther Schmidt wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hi,
>
> I've developed the code following code but I have one problem: How do I
> identify the button that was pressed?
>
> When I specify the callback function to a button do I need to pass
> specific arguments, in short: I don't know how it's done.
>
> ;; model
>
> (define pad
> '((1 2 3)
> (4 5 6)
> (7 8 9)
> (\# 0 *)))
>
> (define pad2
> '((1 2 3 +)
> (4 5 6 -)
> (7 8 9 *)
> (0 = \. /)))
>
>
> ;; view
>
> (define md (make-message "n"))
>
> (define (pad->gui title a-list)
> (cons
> (list (make-message title))
> (cons (list md)
> (traverse a-list))))
>
> (define (traverse a-list)
> (cond
> ((empty? a-list) empty)
> ((list? a-list)
> (cons (traverse (first a-list))
> (traverse (rest a-list))))
> (else
> (make-button
> (cond
> ((symbol? a-list) (symbol->string a-list))
> (else (number->string a-list)))
> test))))
>
> ;; controller
>
> (define (test e)
> (draw-message md "2"))
>
> (create-window (pad->gui "PHONE" pad))
>
>
>
> Cheers
>
> Guenther
>
>
>