[racket] This is too clumsy. Is there a better way?

From: Justin Zamora (justin at zamora.com)
Date: Fri Jul 13 09:21:56 EDT 2012

You can use something like this:

(define (all-lower-case? str)
  (string=? str (string-downcase str)))

> (all-lower-case? "haha")
> (all-lower-case? "haHa")


On Fri, Jul 13, 2012 at 9:02 AM, Rouben Rostamian <rostamian at umbc.edu> wrote:
> 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)))))
> This looks rather clumsy to me.  I am converting the string into
> a list of characters, then I check the case of each character
> and issue the requisite verdict.  It seems to me that there
> ought to be a neater way.  Any suggestions?
> --
> Rouben Rostamian
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.