;; 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-vanilla-reader.ss" "deinprogramm")((modname map-list) (read-case-sensitive #f) (teachpacks ()) (deinprogramm-settings #(#f write repeating-decimal #f #t none explicit #f ()))) ; Transformiere eine Liste in eine andere, indem auf jedes Element ; eine Funktion angewendet wird (: map-list ((%a -> %b) (list-of %a) -> (list-of %b))) (check-expect (map-list square empty) empty) (check-expect (map-list square (list 1 2 3 4)) (list 1 4 9 16)) (check-expect (map-list (lambda (x) (+ x 1)) (list 1 2 3)) (list 2 3 4)) (check-expect (map-list not (list #f #t)) (list #t #f)) (check-expect (map-list positive? (list 1 -4 3)) (list #t #f #t)) ; Konstruktionsschablone für Listen: #;(define map-list (lambda (fun xs) (cond ((empty? xs) ...) ((cons? xs) ...(first xs) ...(map-list fun (rest xs)) ...)))) (define map-list (lambda (fun xs) (cond ((empty? xs) empty) ((cons? xs) (cons (fun (first xs)) (map-list fun (rest xs))))))) (define square (lambda (x) (* x x)))