Hi, I’ve been using Python for a long time and am starting to learn Julia a bit by going through the MIT course as well as Exercism exercises.
I recently came across a simple ROT13 exercise in Exercism. As part of the solution, I need to do slightly different things based on if a character is uppercase, lowercase, or some other non-alphabetic character.
I don’t want to actually show the solution code here since it’s an exercise and that’s not the point of this post, but my basic structure is simply:
function rotate(k, c::AbstractChar)
if isuppercase(c)
# do uppercase ROT-k calculation
elseif islowercase(c)
# do lowercase ROT-k calculation
else
# do nothing
end
end
function rotate(k, str::AbstractString)
# do entire string ROT-k calculation
end
Now, if I do typeof('a')
I just get Char
, but if I do Char('a')
I get:
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
And I’m wondering if there’s any way to dispatch on any of the given information there, for example to do something like(guessing at syntax here):
rotate(k, str::AbstractString) = # do entire string ROT-k calculation
rotate(k, c::AbstractChar) = # do nothing
rotate(k, c::Unicode{Ll}) = # do lowercase ROT-k calculation
rotate(k, c::Unicode{Lu}) = # do uppercase ROT-k calculation
And if so, does this have any performance(or other) implications, positive or negative?
Thanks!