[fpc-pascal] Case statements without constants?

R0b0t1 r030t1 at gmail.com
Mon Oct 29 11:24:59 CET 2018


On Mon, Oct 29, 2018 at 11:20 AM Michael Van Canneyt
<michael at freepascal.org> wrote:
>
> > I tried today to make a case that used variables instead of constants and
> > was surprised to get an error. I’m sure this been true since the 80’s but
> > why don’t cases allow variables??? I thought a case statement was just a
> > group of if..else blocks in succession.
>
> Case has never allowed variables.
>
> and it is also not a group of if..else blocks. The compiler uses jump
> tables when possible etc when it encounters a case.
>

I think it is important to differentiate between a language feature
and its common implementation. Perhaps case statements with variables
make sense? Of course, that doesn't mean anyone is going to add them.

I suggest the OP look up pattern matching. Scala may be more readable
than Haskell, and there is also OCaml.

Cheers,
    R0b0t1


More information about the fpc-pascal mailing list