Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding Types
#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
You can’t perform that action at this time.