Scheme 球拍-大写 ;定义将小写字符转换为大写字符的过程char_toupper (定义char_toupper(lambda(myChar)) ;将x定义为myChar的ASCII值 (定义x(字符->整数myChar)) ;将y定义为x-32 (定义y(-x 32)) ;while x的if语句小于91(已为大写) (如果(x 96) ;然后显示与y给定的ASCII值相等的字符 (显示(整型->字符y‘‘‘‘‘‘‘)’) (定义字符串_toupper(lambda(myString newString i) (如果(

Scheme 球拍-大写 ;定义将小写字符转换为大写字符的过程char_toupper (定义char_toupper(lambda(myChar)) ;将x定义为myChar的ASCII值 (定义x(字符->整数myChar)) ;将y定义为x-32 (定义y(-x 32)) ;while x的if语句小于91(已为大写) (如果(x 96) ;然后显示与y给定的ASCII值相等的字符 (显示(整型->字符y‘‘‘‘‘‘‘)’) (定义字符串_toupper(lambda(myString newString i) (如果(,scheme,racket,Scheme,Racket,这会将每个字符转换为大写,并显示它。但是我不断地得到一个错误,我能找到它。任何帮助。谢谢在球拍中,您必须在时编写,而不是在单臂情况下编写如果 也就是说,将下面表达式中的if更改为when ; defining the procedure char_toupper to convert a lower case character to upper case (define char_toupper (lambda (myChar) ; definin

这会将每个字符转换为大写,并显示它。但是我不断地得到一个错误,我能找到它。任何帮助。谢谢

在球拍中,您必须在时编写
,而不是在单臂情况下编写
如果

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

; 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)

还请注意,这是内置的。

并且您不断得到的错误是?字符串长度:预期的合同冲突:字符串?读取不一定返回字符串。它返回一个值,但该值可能是字符串、符号、数字、列表或。。。取决于用户键入的内容。所以您可能想改用read line:另外char_toupper函数实际上返回void…类似地,char upcase也是内置的:
(if (> x 96)
    ; then display the character equivalent to the ASCII value given by y
    (display (integer->char y)))