From 3b77ff5ca7f44e83af478959ed6a2c19328dbde4 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 15 May 2017 00:03:27 -0700 Subject: [PATCH] custom printer --- pitfall/pitfall/helper.rkt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pitfall/pitfall/helper.rkt b/pitfall/pitfall/helper.rkt index 75c628e3..08b1dfdf 100644 --- a/pitfall/pitfall/helper.rkt +++ b/pitfall/pitfall/helper.rkt @@ -133,10 +133,20 @@ (define-syntax-rule (test-when cond expr) (if cond (raise-test-exn expr) expr)) +(define string% + (class* object% (writable<%>) + (super-new) + (init-field [data #f]) + (define (get-string) + (with-handlers ([exn:fail:object? (λ (exn) data)]) + (send this toString))) + (define/public (custom-write port) (write (get-string) port)) + (define/public (custom-display port) (display (get-string) port)))) + (define mixin-tester% (class object% (super-new) - (define/public (addContent val) val))) + (define/public (addContent val) (make-object string% val)))) (define-syntax (as-method stx) (syntax-case stx ()