Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-07

List of chars for case

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

Is there a way to make a constant for a list of chars which I can use in a case statement? I’ve got a bunch of code duplication happening I’d like to clean up.

const
  TChars = ('[', ']', '(', ')', '{', '}', '=', ‘:’);

case c of
TChars:
...

Regards,
Ryan Joseph

Reply by email

R0b0t1
to Ryan Joseph
Ryan Joseph wrote 10 lines
Is there a way to make a constant for a list of chars which I can use in a case statement? I’ve got a bunch of code duplication happening I’d like to clean up. const TChars = ('[', ']', '(', ')', '{', '}', '=', ‘:’); case c of TChars: ...

I suspect you may need to use sets and the "in" operator.

Reply by email

Dennis
to Ryan Joseph: Is there a way to make a constant for a list of chars which I can use in a case…
Ryan Joseph wrote 14 lines
Is there a way to make a constant for a list of chars which I can use in a case statement? I’ve got a bunch of code duplication happening I’d like to clean up. const TChars = ('[', ']', '(', ')', '{', '}', '=', ‘:’); case c of TChars: ... Regards, Ryan Joseph
   case c of
      '[', ']', '(', ')', '{', '}', '=', ':' : result := true;
   end;

Dennis

Reply by email

Ryan Joseph
to leledumbo
On Jul 2, 2018, at 10:55 PM, leledumbo via fpc-pascal wrote: Only through macro ATM

Yeah I cheated and used a macro. ...and that’s why we should allow for macros as a fail safe in times of distress...

Regards,
Ryan Joseph

Reply by email