"with" still sucks + removing features + adding features

Derek Parnell derek at psych.ward
Mon May 18 19:41:00 PDT 2009


On Mon, 18 May 2009 14:33:29 -0400, bearophile wrote:

> 3) If you want to add a second kind of switch, then let's
>    add a truly safer one, with no fall-through, etc.

**WARNING** an off-topic aside follows ...

The next version of the Euphoria programming language has implemented
'switch'. The language only had 'if-elsif-' constructs before. The new
'switch' has this syntax ...

   'switch' ['with fallthru'] 'do'
       'case' EXPRESSION 'then'
           STATEMENTS
           [( 'break' | 'fallthru')]
       . . .
   'end' 'switch'

Yeah, I know is not a punctuation-heavy language like D, but get over that
for now. The point is that by default the cases do not fallthru. If you
want cases to fallthru by default you need to add the 'with fallthru'
qualifier. Furthermore, each case can have 'break' to explicitly prevent it
falling thru to the next case, or 'fallthru' to explicitly cause it to fall
thru to the next case. If you have neither, then it does the default action
indicated on the 'switch' line.

procedure classify(char c)
    write("You passed ")
    switch c do
       case '#' then
          writeln("a hash sign.")

       case in "012345679" then
          writeln("a digit.")

       case 'A' to 'Z', 'a' to 'z' then
          writeln("an ASCII character.")

       case '.', ',', ':', ';', '!', '?' then
          writeln("a punctuation mark.")

       case else
          writeln("quite a character!")

    end switch
end procedure

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list