I'm writing a program where it asks me to convert all the uppercase letters in str to lowercase and lowercase to uppercase, and all other characters remain the same. Below is my code:
(define (switch-case str)
(list->string (switch-char (string->list str))))
(define (switch-char loc)
(cons
(cond
[(empty? (first loc)) empty]
[(char-lower-case? (first loc)) (char-upcase (first loc))]
[(char-upper-case? (first loc)) (char-downcase (first loc))]
[else (first loc)]) (switch-char (rest loc))))
And the error message for (switch-case "ABC") is:
first: expects a non-empty list; given: empty
Can someone help me with this? I don't know which part of the code is wrong:(