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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Jul 13 14:29:07 EDT 2012

> Welcome to Racket v5.3.0.14.
> > (require lang/htdp-beginner)
> > (string-lower-case? "ABC")
> #f
> > (string-lower-case? "aBC")
> #f
> > (string-lower-case? "abc")
> #t

http://pre.racket-lang.org/docs/html/htdp-langs/beginner.html#(def._htdp-beginner._((lib._lang/htdp-beginner..rkt)._string-upper-case~3f))




On Jul 13, 2012, at 9:02 AM, Rouben Rostamian 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.