Created
November 2, 2019 23:25
-
-
Save chelseatroy/39a41d0ed44a147b96d0e9bfdb728d4a to your computer and use it in GitHub Desktop.
Adding Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (attach-tag tag item) | |
(cons tag item)) | |
(define (contents tagged-item) | |
(cdr tagged-item)) | |
... | |
(define (bob-width box) | |
(car (cdr (contents box)))) | |
(define (bob-height box) | |
(cdr (cdr (contents box)))) | |
... | |
(define (alice-width box) | |
(abs (- (car (cdr (contents box))) | |
(car (car (contents box)))))) | |
(define (alice-height box) | |
(abs (- (cdr (cdr (contents box))) | |
(cdr (car (contents box)))))) | |
... | |
(define (bob-box? box) | |
(if (= (car box) 'bob-box) true false)) | |
(define (alice-box? box) | |
(if (= (car box) 'alice-box) true false)) | |
(define (width box) | |
(cond ((bob-box? box) (bob-width box)) | |
((alice-box? box) (alice-width box)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment