;;; Datentyp "spider" ;;; Datentyp für die Darstellung von Spinnen (define-struct spider (legs poisonousness space)) ;;; Datentyp "elephant" ;;; Datentyp für die Darstellung von Elefanten (define-struct elephant (space)) ;;; Datentyp "snake" ;;; Datentyp für die Darstellung von Schlangen (define-struct snake (poisonousness space)) ;;; Datentyp "monkey" ;;; Datentyp für die Darstellung von Affen (define-struct monkey (intelligence space)) ;;; Datentyp "animal" ;;; Ein Wert vom Typ animal ist entweder ein ;;; 1. spider oder ;;; 2. elephant oder ;;; 3. snake oder ;;; 4. monkey ;;; SIGNATUR ;;; animal?: scheme-value -> boolean ;;; ERKLÄRUNG ;;; BEISPIEL ;;; DEFINITION (define animal? (lambda (a) (or (spider? a) (elephant? a) (snake? a) (monkey? a)))) ;;; SIGNATUR ;;; animal-fits?: animal number -> boolean ;;; ERKLÄRUNG ;;; (animal-fits? animal space) gibt #t zurück, falls das Zootier animal ;;; in einer Transportkiste mit der Seitenlänge space transportiert werden kann. ;;; BEISPIEL ;;; (animal-fits? (make-elephant 3) 2) ;;; => false ;;; DEFINITION (define animal-fits? (lambda (animal space) (cond ((spider? animal) (<= (spider-space animal) space)) ((elephant? animal) (<= (elephant-space animal) space)) ((snake? animal) (<= (snake-space animal))) ((monkey? animal) (<= (monkey-space animal) space))))) ;;; SIGNATUR ;;; animal-poisonousness: animal -> number ;;; ERKLÄRUNG ;;; (animal-poisonousness animal) gibt an, wie gefährlich das von dem Tier ;;; abgesonderte Gift ist. Wenn das Tier kein Gift absondert, wird 0 ;;; zurückgegeben; ;;; BEISPIELE ;;; (animal-poisonousness (make-elephant 3)) ;;; => 0 ;;; (animal-poisonousness (make-snake 3 0.5)) ;;; => 3 ;;; DEFINITION (define animal-poisonousness (lambda (animal) (cond ((spider? animal) (spider-poisonousness animal)) ((snake? animal) (snake-poisonousness animal)) ((elephant? animal) 0) ((monkey? animal) 0))))