首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >球拍-UpperCase

球拍-UpperCase
EN

Stack Overflow用户
提问于 2012-11-11 06:29:48
回答 1查看 2.4K关注 0票数 0
代码语言:javascript
复制
; defining the procedure char_toupper to convert a lower case character to upper case
(define char_toupper (lambda (myChar)
                       ; defining x as the ASCII value of myChar
                       (define x (char->integer myChar))
                       ; defining y as x-32
                       (define y (- x 32))
                       ; if statement for while x is less than 91 (already uppercase)
                       (if (< x 91)
                            ; if it is already uppercase, just display it
                            (display myChar)
                            ; otherwise, if x is greater than 96 (lowercase)
                            (if (> x 96)
                                ; then display the character equivalent to the ASCII value given by y
                                (display (integer->char y))))))

(define string_toupper (lambda (myString newString i)       
                         (if (< i (string-length myString))
                             (string_toupper myString (string-append newString (char_toupper (string-ref myString i))) (+ 1 i)))

                         (display newString)))
(string_toupper (read) "" 0)

这会将每个字符转换为大写,并显示出来。但我一直收到一个错误,我可以找到它。有什么帮助吗。谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-11-11 06:43:26

在球拍中,您必须在单臂情况下编写when而不是if

也就是说,将以下表达式中的if更改为when

代码语言:javascript
复制
(if (> x 96)
    ; then display the character equivalent to the ASCII value given by y
    (display (integer->char y)))

还要注意的是,string-upcase是内置的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13326694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档