From 34f3fac6a50c2622e9d80c103642f881a17dc5b6 Mon Sep 17 00:00:00 2001 From: Stephen Bloch Date: Thu, 14 Jul 2011 13:07:23 -0400 Subject: [PATCH] Corrected the grammar in check-arg and check-result to follow the English convention of "a" before a consonant and "an" before a vowel. There will presumably be pathological cases, but this should cover 95% of the situations. --- collects/htdp/error.rkt | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/collects/htdp/error.rkt b/collects/htdp/error.rkt index 21883517a1..3586a7d39f 100644 --- a/collects/htdp/error.rkt +++ b/collects/htdp/error.rkt @@ -13,6 +13,23 @@ (define (natural? w) (and (number? w) (integer? w) (>= w 0))) +; starts-with-vowel? : string -> boolean +(define (starts-with-vowel? s) + (and + (not (string=? s "")) + (member (string-ref s 0) (list #\a #\e #\i #\o #\u)))) + +; add-article : anything -> string +; (add-article 'color) should be "a color" +; (add-article 'acronym) should be "an acronym" +(define (add-article thing) + (let ((s (format "~a" thing))) + (string-append + (if (starts-with-vowel? s) + "an " + "a ") + s))) + ;; (_ -> Boolean) (listof X) -> (union X false) (define (find-non pred? l) (let ([r (filter (compose not pred?) l)]) @@ -81,7 +98,8 @@ (define (check-result pname pred? expected given . other-given) (if (pred? given) given - (tp-error pname "is expected to return a ~a, but it returned ~v" expected + (tp-error pname "is expected to return ~a, but it returned ~v" + (add-article expected) (if (pair? other-given) (car other-given) given)))) @@ -114,8 +132,8 @@ ;; check-arg : sym bool str (or/c str non-negative-integer) TST -> void (define (check-arg pname condition expected arg-posn given) (unless condition - (tp-error pname "expects a ~a as ~a argument, given ~e" - expected + (tp-error pname "expects ~a as ~a argument, given ~e" + (add-article expected) (spell-out arg-posn) given)))