Discussion:
[fpc-pascal] List of chars for case
Ryan Joseph
2018-07-01 22:51:08 UTC
Permalink
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

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists
R0b0t1
2018-07-02 00:19:29 UTC
Permalink
Post by 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
...
I suspect you may need to use sets and the "in" operator.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo
Dennis
2018-07-02 06:48:54 UTC
Permalink
Post by 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
...
Regards,
Ryan Joseph
  case c of
     '[', ']', '(', ')', '{', '}', '=', ':' : result := true;
  end;



Dennis
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/
Mattias Gaertner
2018-07-02 08:07:54 UTC
Permalink
On Sun, 1 Jul 2018 16:51:08 -0600
Post by 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
That would be useful.

Mattias
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/
Ryan Joseph
2018-07-02 14:59:00 UTC
Permalink
Post by Mattias Gaertner
That would be useful.
So it can’t be done?

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepasca
leledumbo via fpc-pascal
2018-07-03 04:55:37 UTC
Permalink
Post by Ryan Joseph
So it can’t be done?
Only through macro ATM, I believe. Note that case statement body does NOT
expect a set (it expects values, list of values and/or range of values),
despite the very similar look (missing enclosing angle brackets only), hence
the inability to do what you want.
Ryan Joseph
2018-07-03 15:16:53 UTC
Permalink
Post by leledumbo via fpc-pascal
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

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.

Loading...