[racket] This is too clumsy. Is there a better way?
Thank you all who responded to my question about possible
improvements on my `all-lower-case?' function. I was surprised
by the large variety of ways that it could be done and learned
something new from each of the respondents. This is a very
helpful mailing list.
--
Rouben Rostamian
---- original message -------------------------------------------
From: Rouben Rostamian <rostamian at umbc.edu>
Date: Fri, 13 Jul 2012 09:02:07 -0400
Subject: [racket] This is too clumsy. Is there a better way?
The function `all-lower-case?' defined below takes a string and
returns #f if the string has at least one uppercase alphabetic
character, else returns #t.
Examples:
(all-lower-case? "asdf12#@") => #t
(all-lower-case? "asDf12#@") => #f
Here is how I have written it:
(define (all-lower-case? str)
(not (memq #t
(map (lambda (i)
(if (and (char-alphabetic? i) (char-upper-case? i))
#t #f))
(string->list str)))))