;; 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 mlist) (read-case-sensitive #f) (teachpacks ()) (deinprogramm-settings #(#f write repeating-decimal #t #t none explicit #f ()))) ; Dieses Modul stellt veränderbare Listen zur Verfügung (provide mlist-of mcons mcons? mfirst mrest set-mfirst! set-mrest!) (define-record-procedures-parametric-2 nonempty-mlist nonempty-mlist-of mcons mcons? ((mfirst set-mfirst!) (mrest set-mrest!))) ; Signaturkonstruktor für Listen: (define mlist-of (lambda (sig) (signature (mixed empty-list (nonempty-mlist-of sig (mlist-of sig)))))) (: mcons (%a (mlist-of %a) -> (nonempty-mlist-of %a (mlist-of %a)))) (: mcons? (any -> boolean)) (: mfirst ((nonempty-mlist-of %a (mlist-of %a)) -> %a)) (: set-mfirst! ((nonempty-mlist-of %a (mlist-of %a)) %a -> unspecific)) (: mrest ((nonempty-mlist-of %a (mlist-of %a)) -> (mlist-of %a))) (: set-mrest! ((nonempty-mlist-of %a (mlist-of %a)) (mlist-of %a) -> unspecific)) ; Umwandlung veränderbare Listen -> "normale" Listen (: mlist->list ((mlist-of %a) -> (list-of %a))) (define mlist->list (lambda (xs) (if (empty? xs) xs (cons (mfirst xs) (mlist->list (mrest xs)))))) (define xs (mcons 1 (mcons 2 empty))) (define xs1 (mcons xs xs)) (define xs2 (mcons (mcons 1 (mcons 2 empty)) (mcons 1 (mcons 2 empty)))) ; Ändere das erste Element des ersten Elements (dies muss eine Liste sein!) ; auf den Wert 9 (define set-ff-9 (lambda (xs) (begin (set-mfirst! (mfirst xs) 9) xs)))