improve ->string

pull/2/head
Matthew Butterick 11 years ago
parent ad72822c04
commit a5e1ee9290

@ -24,9 +24,10 @@
;; general way of coercing to string
(define+provide/contract (->string x)
(any/c . -> . string?)
(if (string? x)
x ; fast exit for strings
(try
(cond
[(string? x) x]
[(equal? '() x) ""]
[(symbol? x) (symbol->string x)]
[(number? x) (number->string x)]
@ -34,7 +35,7 @@
[(path? x) (path->string x)]
[(char? x) (format "~a" x)]
[else (error)]) ; put this last so other xexprish things don't get caught
(except [exn:fail? (make-coercion-error-handler 'string x)])))
(except [exn:fail? (make-coercion-error-handler 'string x)]))))
;; general way of coercing to html

Loading…
Cancel
Save