Improvement to switch-case statement

bearophile bearophileHUGS at lycos.com
Wed Dec 31 18:09:07 PST 2008


Michel Fortin Wrote:
> Imagine writting:
> 
> 	case 'a'..'{':
> 	case 'A'..'[':
> 
> Concistent, yes; but not very appealing. What you want to be able to 
> write is this:
> 
> 	case 'a'..'z':
> 	case 'A'..'Z':
> 
> But then it doesn't work as elsewhere in the language anymore.

Ruby solves the problem having two different syntaxed, .. and ... for open and closed intervals. But I don't like it much, it's easy to miss the extra point.

An easy solution:

    case 'a' .. 'z'+1:
    case 'A' .. 'Z'+1:

Bye,
bearophile



More information about the Digitalmars-d mailing list