;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname fish) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ()))) (require htdp/gui) (define-struct fish (weight)) (define (create-fish init-size) (local [ ; The model: (define FISH (make-fish init-size)) ; feed : num -> num ; ... (define (feed n) (begin (set-fish-weight! FISH (+ n (fish-weight FISH))) (fish-weight FISH))) ; The view: (define msg (make-message (number->string (fish-weight FISH)))) ; The control: (define (feed-button n) (make-button (string-append "Feed " (number->string n)) (lambda (evt) (draw-message msg (number->string (feed n))))))] (begin (create-window (list (list msg) (list (feed-button 1) (feed-button 3)))) FISH))) (define samuel (create-fish 3)) (define sam samuel) (define gil (create-fish 7))