From 25fbd16843e71621c0a4d653f2e9c2652c6dc3aa Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 21 Mar 2014 17:10:30 -0700 Subject: [PATCH] try macrostring --- coerce/value.rkt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/coerce/value.rkt b/coerce/value.rkt index 022138c..20071f3 100644 --- a/coerce/value.rkt +++ b/coerce/value.rkt @@ -19,6 +19,19 @@ [else (len x)]))) +(provide ->macrostring) +(define-syntax-rule (->macrostring x) + (if (string? x) + x ; fast exit for strings + (with-handlers ([exn:fail? (make-coercion-error-handler 'string (format "~a (result of ~a" x 'x))]) + (cond + [(equal? '() x) ""] + [(symbol? x) (symbol->string x)] + [(number? x) (number->string x)] + [(path? x) (path->string x)] + [(char? x) (format "~a" x)] + [else (error)])))) + (define+provide (->string x) (if (string? x) x ; fast exit for strings