add void case to string coercion

pull/2/head
Matthew Butterick 10 years ago
parent b32c555a89
commit 2d48f83503

@ -1,10 +1,8 @@
#lang racket/base
(require (for-syntax racket/base racket/syntax))
(require net/url xml racket/set racket/contract racket/sequence racket/stream racket/dict)
(require net/url racket/set racket/contract racket/sequence racket/stream racket/dict)
(require "len.rkt" "define.rkt")
(define (make-coercion-error-handler target-format x)
(λ(e) (error (format "Cant convert ~a to ~a" x target-format))))
@ -26,7 +24,7 @@
x ; fast exit for strings
(with-handlers ([exn:fail? (make-coercion-error-handler 'string (format "~a (result of ~a" x 'x))])
(cond
[(equal? '() x) ""]
[(or (equal? '() x) (void? x)) ""]
[(symbol? x) (symbol->string x)]
[(number? x) (number->string x)]
[(path? x) (path->string x)]
@ -38,7 +36,7 @@
x ; fast exit for strings
(with-handlers ([exn:fail? (make-coercion-error-handler 'string x)])
(cond
[(equal? '() x) ""]
[(or (equal? '() x) (void? x)) ""]
[(symbol? x) (symbol->string x)]
[(number? x) (number->string x)]
[(path? x) (path->string x)]

@ -5,6 +5,7 @@
(check-equal? (->string "foo") "foo")
(check-equal? (->string '()) "")
(check-equal? (->string (void)) "")
(check-equal? (->string 'foo) "foo")
(check-equal? (->string 123) "123")
;(check-equal? (->string (string->url "foo/bar.html")) "foo/bar.html")

Loading…
Cancel
Save