Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 2, 2019 23:06
Show Gist options
  • Save chelseatroy/1d987910a8489a9a26b21be51ef92c11 to your computer and use it in GitHub Desktop.
Save chelseatroy/1d987910a8489a9a26b21be51ef92c11 to your computer and use it in GitHub Desktop.
Two Box Implementations
#lang racket
(define (make-bob-box x y w h)
(attach-tag 'bob-box (cons (cons x y) (cons w h))))
(define (bob-width box)
(car (cdr (box))))
(define (bob-height box)
(cdr (cdr (box))))
(define (make-alice-box x1 y1 x2 y2)
(cons (cons x1 y1) (cons x2 y2)))
(define (alice-width box)
(abs (- (car (cdr (box))
(car (car (box)))))
(define (alice-height box)
(abs (- (cdr (cdr (box))
(cdr (car (box)))))
(define (alice-area box)
(* (alice-width box)
(alice-height box)))
(define a (make-alice-box 1 2 3 4))
(define b (make-bob-box 1 2 3 4))
(alice-area a) ;--> 4
(bob-area b) ;--> 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment