Created
September 9, 2014 04:01
-
-
Save samdphillips/d3448919252d2c245a29 to your computer and use it in GitHub Desktop.
Integrating Racket Classes and Struct Generics
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/base | |
(require racket/block | |
racket/class | |
racket/generic) | |
(define gar<%> | |
(interface () | |
do-foo | |
do-bar)) | |
(define-generics gar | |
#:defaults | |
([(lambda (x) (is-a? x gar<%>)) | |
(define gen-foo (generic gar<%> do-foo)) | |
(define gen-bar (generic gar<%> do-bar)) | |
(define (gar-foo x) (send-generic x gen-foo)) | |
(define (gar-bar x y) (send-generic x gen-bar y)) | |
]) | |
[gar-foo gar] | |
[gar-bar gar y]) | |
(define gar% | |
(class* object% (gar<%>) | |
(define/public (do-foo) 'foo) | |
(define/public (do-bar y) (list 'bar y)) | |
(super-new))) | |
(define bar% | |
(class gar% | |
(define/override (do-foo) 'foo2) | |
(super-new))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment