"with" still sucks + removing features + adding features
Derek Parnell
derek at psych.ward
Mon May 18 19:55:58 PDT 2009
On Mon, 18 May 2009 19:38:05 -0500, Andrei Alexandrescu wrote:
> I like my syntax better than all you mentioned, by a mile.
Problem: Define a syntax that indicates a specific range of values for a
single case statement.
Constraints:
(1) No new keywords permitted.
(2) No new operators permitted.
(3) Must indicate an *inclusive* range
(4) A range has an explicit starting value and ending value
(5) A range has an implicit step value of 1.
(6) Must not be keystroke-heavy
(7) Must be easy to read
(8) Must be easy to remember while writing
(9) Must not be ambiguous with existing syntax
(10) Must be consistent with existing syntax
(11) Must take the general form ...
'case' RANGE ':'
Andrei ...
case FIRST .. case LAST :
[[ -(8)- The second 'case' is easy to forget to write ]]
[[ -(10)- The ".." means exclusive range elsewhere but not here ]]
bearophile ...
case FIRST .. LAST+1 :
[[ -(8)- The +1 is easy to forget to write ]]
JB (first pass)
case FIRST .. LAST :
[[ -(10)- inconsistent with exclusive range syntax]]
So just as a thought without a lot of adademic introspection
derek ...
case [FIRST ; LAST] :
sample code ...
void classify(char c) {
write("You passed ");
switch (c) {
case '#':
writeln("a hash sign.");
break;
case ['0' ; '9']:
writeln("a digit.");
break;
case ['A' ; 'Z'], ['a' ; 'z']:
writeln("an ASCII character.");
break;
case '.', ',', ':', ';', '!', '?':
writeln("a punctuation mark.");
break;
default:
writeln("quite a character!");
break;
}
}
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
More information about the Digitalmars-d
mailing list