Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Type Registry
#lang racket
(define (register h method tag function)
(hash-set! h (list tag method) function))
(define (lookup h key)
(hash-ref h key))
(define h (make-hash))
(register h 'alice-box 'width alice-width)
(register h 'bob-box 'width bob-width)
(define (width box)
((lookup h (list 'width (car box))) box))
(define (height box)
((lookup h (list 'height (car box))) box))
(define b (make-bob-box 1 2 3 4))
(width b) ;--> 3
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.