Reputation: 1
; 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)
This converts each character to upper case, and displays it. But I keep getting an error and I can find it. Any help. Thanks
Upvotes: 0
Views: 3244
Reputation: 31147
In Racket you must write when
instead of if
in the one-armed case.
That is, change the if
in the following expression to when
.
(if (> x 96)
; then display the character equivalent to the ASCII value given by y
(display (integer->char y)))
Also note that string-upcase is builtin.
Upvotes: 2