-
-
Save capfredf/e2375151ad3c2c19209daa5f63db643d to your computer and use it in GitHub Desktop.
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
(define-generics printable | |
(gen-print printable [port]) | |
(gen-port-print port printable) | |
(gen-print* printable [port] #:width width #:height [height])) | |
(define-struct bool (v) | |
#:methods gen:printable | |
[(define/generic super-print gen-print) | |
(define (gen-print n [port (current-output-port)]) | |
(fprintf port "Bool: ~a" (bool-v n))) | |
(define (gen-port-print port n) | |
(gen-print n port) | |
(super-print n port)) | |
(define (gen-print* n [port (current-output-port)] | |
#:width w #:height [h 0]) | |
(fprintf port "Bool (~ax~a): ~a" w h (bool-v n)))]) | |
(define-struct num (v) | |
#:methods gen:printable | |
[(define/generic super-print gen-print) | |
(define (gen-print n [port (current-output-port)]) | |
(fprintf port "Num: ~a" (num-v n))) | |
(define (gen-port-print port n) | |
;; (gen-print (bool (< (num-v n) 10)) port) ;; error, this is a call to gen-print on L22 | |
(super-print (bool (< (num-v n) 10)) port)) | |
(define (gen-print* n [port (current-output-port)] | |
#:width w #:height [h 0]) | |
(fprintf port "Num (~ax~a): ~a" w h (num-v n)))]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment