[fpc-devel] "case" with range stupidities
Daniël Mantione
daniel.mantione at freepascal.org
Thu Feb 15 15:46:10 CET 2007
Op Thu, 15 Feb 2007, schreef Vinzent Hoefler:
> So if the case label is considered a set why can't I use a set constant
> (see the commented lines above)
Because a normal set is limited by brackets:
const a = [1,2,5];
b = [a,7,8,9]; {This is not allowed.}
b = [a]+[7,8,9]; {But this is.}
Because, in a case statement you are already "inside" the brackets:
case x of
1,2,5: {No brackets.}
... you have a syntax problem for allowing set constants (what does
"[1,2,4],9" mean?). If you would design a syntax for it, you could allow
set constants.
> and if I do the range thing, which
> compiles, it does not consider the value of the constant but rather the
> range of its /type/...?
No, low(x) is a constant.
> Seems to me that case labels are very special things, at least.
>
> Another oddity would be a for loop:
>
> for Bla := One to Five do ...
>
> would be a range only, yes? (Apart from the fact that - due to the "to"
> keyword - really isn't).
It is a range, but one also needs to specify the direction (to/downto), so
it is logical that for-loops don't use .. syntax.
> So wouldn't it be easier to write
>
> | for Bla := X do ...
>
> here, when X is some range type, I'd like to iterate over? Again I have
> to Write "Low (X) to High (X)" quite similar to the "case" case.
It would be easier but you would miss the direction information.
> I suppose changing that behaviour regarding range types is not an option
> at all, so I'd ask for some other improvement:
>
> *deep breath*
>
> What about a compiler built-in like Low() and High() called Range()
> where its return type indicates something that would be compatible to a
> case and for label and just denote the range of the whole type?
>
> Basically a short cut to the "Low (Type) ..|to High (Type)" expression,
> but without the possible pitfall of writing
>
> Low (Type) .. High (A_Similar_And_Unfortunately_Compatible_Type)
>
> and thus being less error-prone...?
It looks okay, but does this pitfall actually exist?
low(colour)..high(wind_direction) would be a type violation.
> I mean, doing:
>
> |for Bla := Range (X) do
See direction problem.
> or
>
> |case Bla in
> |Range (X): ...
>
> doesn't actually look unreadable to me...
Indeed, but do you solve a problem? I.e. I can imagine some kind of syntax
to allow set constants would help, but this seems mostly a typing
shortcut.
Daniël
More information about the fpc-devel
mailing list