;; Die ersten drei Zeilen dieser Datei wurden von DrRacket eingefügt. Sie enthalten Metadaten ;; über die Sprachebene dieser Datei in einer Form, die DrRacket verarbeiten kann. #reader(lib "DMdA-assignments-reader.ss" "deinprogramm")((modname account) (read-case-sensitive #f) (teachpacks ()) (deinprogramm-settings #(#f write repeating-decimal #t #t none explicit #f ()))) ; Aktueller Kontostand (: balance natural) (define balance 130) ;(: withdraw (natural -> natural)) #;(define withdraw (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) (violation "No money!")))) ; Konto abheben mit lokalen Zustand (define new-withdraw (letrec ((balance 130)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) (violation "No money!"))))) ; Konto mit einem gegebenen Kontostand erzeugen. (: make-withdraw (natural -> (natural -> natural))) (define make-withdraw (lambda (balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) (violation "No money!"))))) (: A1 (natural -> natural)) (define A1 (make-withdraw 130)) (: A2 (natural -> natural)) (define A2 (make-withdraw 130)) (define account-message (signature (one-of "withdraw" "deposit"))) (: make-account (natural -> (account-message -> (natural -> natural)))) (define make-account (lambda (init-amount) (letrec ((balance init-amount) (withdraw (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) (violation "No money!")))) (deposit (lambda (amount) (begin (set! balance (+ balance amount)) balance))) (dispatch (lambda (message) (cond ((string=? message "withdraw") withdraw) ((string=? message "deposit" ) deposit))))) dispatch))) (define acct (make-account 100))