From f733f149f554b9f1275464ab182126df129dcb88 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Wed, 17 Oct 2012 20:26:18 -0400 Subject: [PATCH] fix string-ith's error message; Closes PR 13197 --- collects/lang/private/teachprims.rkt | 6 +++--- collects/tests/htdp-lang/beg-adv.rktl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/collects/lang/private/teachprims.rkt b/collects/lang/private/teachprims.rkt index fd0c6abeac..3bad49ef0b 100644 --- a/collects/lang/private/teachprims.rkt +++ b/collects/lang/private/teachprims.rkt @@ -482,11 +482,11 @@ namespace. (define-teach beginner string-ith (lambda (s n) - (define f "exact integer in [0, length of the given string]") (cerr 'string-ith (string? s) "string" s "first") (cerr 'string-ith (and (number? n) (integer? n) (>= n 0)) NAT n "second") - (let ([l (string-length s)]) - (cerr 'string-ith (< n l) f n "second")) + (define l (string-length s)) + (define f (format "exact integer in [0, ~a) (i.e., less than the length of the given string)" l)) + (cerr 'string-ith (< n l) f n "second") (string (string-ref s n)))) ;; ----------------------------------------------------------------------------- diff --git a/collects/tests/htdp-lang/beg-adv.rktl b/collects/tests/htdp-lang/beg-adv.rktl index a3be217b03..1e50b78f51 100644 --- a/collects/tests/htdp-lang/beg-adv.rktl +++ b/collects/tests/htdp-lang/beg-adv.rktl @@ -321,7 +321,7 @@ (htdp-err/rt-test (string-ith "hell" 4) (exn-type-and-msg exn:fail:contract? - "string-ith: expected an exact integer in [0, length of the given string] for the second argument, but received 4")) + "string-ith: expected an exact integer in [0, 4) (i.e., less than the length of the given string) for the second argument, but received 4")) (htdp-err/rt-test (string-ith 10 4) (exn-type-and-msg exn:fail:contract?