List of chars for case

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

List of chars for case

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

R0b0t1
On Sun, Jul 1, 2018 at 5:51 PM, Ryan Joseph <[hidden email]> wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

Dennis
In reply to this post by Ryan Joseph


Ryan Joseph wrote:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

Mattias Gaertner
In reply to this post by Ryan Joseph
On Sun, 1 Jul 2018 16:51:08 -0600
Ryan Joseph <[hidden email]> wrote:

> 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:

That would be useful.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

Ryan Joseph


> On Jul 2, 2018, at 2:07 AM, Mattias Gaertner <[hidden email]> wrote:
>
> That would be useful.

So it can’t be done?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

Free Pascal - General mailing list
> 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.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: List of chars for case

Ryan Joseph


> On Jul 2, 2018, at 10:55 PM, leledumbo via fpc-pascal <[hidden email]> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal