Re: [fpc-devel] TShiftState as enum
Delphi dowsn't allow sets with ordinal values larger than 255 too: That's incorrect. . Sets are restricted to a maximum of 256 members, but the ordinal values of the members can be higher. As I've already posted: sample code below not compile in any Delphi version. You can try it yourself. type aenum=510..517; aset = set of aenum; begin Writeln(sizeof(aset)); end. Delphi 2005 emits: Borland Delphi for Win32 compiler version 17.0 Copyright (c) 1983,2004 Borland Software Corporation 1.pas(2) Error: E2028 Sets may have at most 256 elements 1.pas(7) ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
Alexey Barkovoy wrote: > Delphi dowsn't allow sets with ordinal values larger than 255 too: That's incorrect. > Borland Delphi Version 13.0 Copyright (c) 1983,99 Inprise Corporation > 1.pas(2) Error: Sets may have at most 256 elements Sets are restricted to a maximum of 256 members, but the ordinal values of the members can be higher. DoDi ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
{$mode delphi} type aenum=510..517; aset = set of aenum; begin Writeln(sizeof(aset)); end. xbla.pp(5,25) Error: illegal type declaration of set elements xbla.pp(10,4) Fatal: There were 1 errors compiling module, stopping Delphi dowsn't allow sets with ordinal values larger than 255 too: Borland Delphi Version 13.0 Copyright (c) 1983,99 Inprise Corporation 1.pas(2) Error: Sets may have at most 256 elements 1.pas(8) = Borland Delphi for Win32 compiler version 17.0 Copyright (c) 1983,2004 Borland Software Corporation 1.pas(2) Error: E2028 Sets may have at most 256 elements 1.pas(8) ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
> > Older Delphi (and TP?) versions implemented sets of subranges (e.g. set > > of 510..515) by "stripping" unused bytes in front of the set. The lowest > > bit in a set variable always had an ordinal value of 2^n, and above set > > would occupy 2 bytes, equaling an set of (504..519). In newer Delphi > > versions the lowest bit exactly corresponds to the lowest ordinal value > > in the range, the above set only occupies one byte (510..517). > > Supported by FPC {$mode delphi} type aenum=510..517; aset = set of aenum; begin Writeln(sizeof(aset)); end. xbla.pp(5,25) Error: illegal type declaration of set elements xbla.pp(10,4) Fatal: There were 1 errors compiling module, stopping Redone with 200..207;-> size = 32 byte = 256 element, so the behaviour of the older version. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
> Older Delphi (and TP?) versions implemented sets of subranges (e.g. set > of 510..515) by "stripping" unused bytes in front of the set. The lowest > bit in a set variable always had an ordinal value of 2^n, and above set > would occupy 2 bytes, equaling an set of (504..519). In newer Delphi > versions the lowest bit exactly corresponds to the lowest ordinal value > in the range, the above set only occupies one byte (510..517). Supported by FPC > AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...) > values for the members. IMO this only is an attempt to closer reflect C > enums, but sets of such enumerated types are not allowed. Supported by FPC ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
RE: [fpc-devel] TShiftState as enum
> > Can somebody enlighten me, what code exactly fails in D6? > What extension does FPC have, that Delphi doesn't have? > > And what "iteration" is desired? I'd use: For Low(x) To High(x)... > > Let me add some more notes, regarding Delphi compatibility: > > Older Delphi (and TP?) versions implemented sets of subranges (e.g. set > of 510..515) i don't want to become heavy, but a subrange it's a subrange and a set is a set. If you'd use Low() and High(), your treating a set as if it were an array, that can be handy sometimes, but strictly speaking, a set has no lower or higher elements. As far as I can remember, in TP, sets were represented with a single byte, that is, the 255 bits were on or off (1 or 0) and represented the existance or the lack of it in the set. AFAICK, you can check for a determinate value in a set, but you can't "navigate" through it as if it were an array. OK, you can use Boolean operators (Union, Intersection, Rest...) and the Include, Exclude functions, etc..., if you feel more comfortable. But there's no firt element, there are no repeated elements, etc... It's a set > AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...) > values for the members. IMO this only is an attempt to closer reflect C > enums, but sets of such enumerated types are not allowed. That's right. Enumerated open types (C-alike), such as (GREY=14, RED, BLUE=21, ...) were introduced in D6, but anyway don?t have nothing to do with sets. > > > I do not ask for any compatibility in these cases, in detail when the > Delphi implementation differs amongst compiler versions. I really don't know, but I guess you are right, it must be a compiler dependence. JMR ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
Marco van de Voort wrote: > > > > TShiftState is defined as TShiftState = set of (...); > > > > > > How can I iterate through the enums? If not, can we split and add an > > > enum: > > > > > > TShiftStateEnum = (...) > > > TShiftState = set of TShiftStateEnum; > > > > > > ? > > > > Of course that is possible. It requires some imagination though (and a feel > > for obfuscated Pascal) > > The example fails in Delphi 6 btw, but works in FPC :-) > Delphi does not allow low/high on sets > > (I vote to keep this FPC extension btw) Can somebody enlighten me, what code exactly fails in D6? What extension does FPC have, that Delphi doesn't have? And what "iteration" is desired? I'd use: For Low(x) To High(x)... Let me add some more notes, regarding Delphi compatibility: Older Delphi (and TP?) versions implemented sets of subranges (e.g. set of 510..515) by "stripping" unused bytes in front of the set. The lowest bit in a set variable always had an ordinal value of 2^n, and above set would occupy 2 bytes, equaling an set of (504..519). In newer Delphi versions the lowest bit exactly corresponds to the lowest ordinal value in the range, the above set only occupies one byte (510..517). AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...) values for the members. IMO this only is an attempt to closer reflect C enums, but sets of such enumerated types are not allowed. I do not ask for any compatibility in these cases, in detail when the Delphi implementation differs amongst compiler versions. DoDi ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
RE: [fpc-devel] TShiftState as enum
> Jose Manuel wrote: > > >I think sets are sets and enumerated types are enumerated types, > and Pascal > >is Pascal- > > > > > Ok, but in pascal the elements in a set can only be of ordered > type anyway. Yes, of course. Maybe I haven't explained myself. Indeed, and you are quite right you'got to define a set of ... (an scalar or enumerated type you've previously defined), but once you're created the set is a "set", there are no order established. I think this is no place nor time to talk about Cantor or whether a subset is part of itself, etc. I just keep on my opinion (until you refuse me with arguments, and I will accept them gratefully, don't doubt on that), that casting that way is against Pascal's spirit (and against Boolean Algebra, I think). Anyway, it's only my opinion. As Michael would say, there are more (and more neccessary) things to do than to speak in this list about angels' sex. JMR ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
Jose Manuel wrote: Well, sets are by definition a kind of bag. No enumeration or any kind of order are suited to sets. Can be handy, I agree, under certain situations, but then we are getting back to C. I think sets are sets and enumerated types are enumerated types, and Pascal is Pascal- Ok, but in pascal the elements in a set can only be of ordered type anyway. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
RE: [fpc-devel] TShiftState as enum
> > > > > > > TShiftStateEnum = (...) > > > > TShiftState = set of TShiftStateEnum; > > > > > > > > ? > > > > > > Of course that is possible. It requires some imagination though (and > > > a feel for obfuscated Pascal) > > > > > > The example fails in Delphi 6 btw, but works in FPC :-) > > Interesting :) > > But in this case: why not simply add one line to classes.pp? > > > > Delphi does not allow low/high on sets > > > > (I vote to keep this FPC extension btw) > > Yes. Well, sets are by definition a kind of bag. No enumeration or any kind of order are suited to sets. Can be handy, I agree, under certain situations, but then we are getting back to C. I think sets are sets and enumerated types are enumerated types, and Pascal is Pascal- > Mattias Only IMHO, of course JMR ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
> [EMAIL PROTECTED] (Marco van de Voort) wrote: > > > > The example fails in Delphi 6 btw, but works in FPC :-) > > Interesting :) Yeah, D2005 for IN syntax is also useful for this (if it operates on sets) > But in this case: why not simply add one line to classes.pp? That is not as much fun! (But I meanwhile already committed and forwarded the tag (so it will be in 1.9.8)) > > Delphi does not allow low/high on sets > > > > (I vote to keep this FPC extension btw) > > Yes. I also submitted it as bug/wishlist to Borland. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
On Thursday 17 February 2005 07:37, Marco van de Voort wrote: > type myset = set of ( a1,a2,a3,a4,a5,a6); > > // workaround types > const > beginmyset=ord(low(myset)); > endmyset=ord(high(myset)); > type > uglyenum = beginmyset..endmyset; > uglyset= set of uglyenum; > > var b : myset; > i : integer; > > begin > b:=[a1,a2,a3]; > for i:=ord(low(myset)) to ord(high(myset)) do > if i in uglyset(b) then writeln(i); > end. "Almost every complex solution ...": type My_Set = set of (a1, a2, a3, a4, a5, a6); // workaround type type Ugly_Enum = Low (My_Set) .. High (My_Set); var b : My_Set; i : Ugly_Enum; begin b := [a1, a2, a3, a5]; for i := Low (b) to High (b) do if i in b then WriteLn (Ord (i)); end. Personally I would prefer to first define the enum and the "set of enum" then. While looking at it: Notice that the code above just reverses the order of the definitions which you need anyway. Quite awkward, I think. Vinzent. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
On Thu, 17 Feb 2005 08:58:01 +0100 (CET) [EMAIL PROTECTED] (Marco van de Voort) wrote: > > > TShiftState is defined as TShiftState = set of (...); > > > > > > How can I iterate through the enums? If not, can we split and add > > > an enum: > > > > > > TShiftStateEnum = (...) > > > TShiftState = set of TShiftStateEnum; > > > > > > ? > > > > Of course that is possible. It requires some imagination though (and > > a feel for obfuscated Pascal) > > > The example fails in Delphi 6 btw, but works in FPC :-) Interesting :) But in this case: why not simply add one line to classes.pp? > Delphi does not allow low/high on sets > > (I vote to keep this FPC extension btw) Yes. Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
> > TShiftState is defined as TShiftState = set of (...); > > > > How can I iterate through the enums? If not, can we split and add an > > enum: > > > > TShiftStateEnum = (...) > > TShiftState = set of TShiftStateEnum; > > > > ? > > Of course that is possible. It requires some imagination though (and a feel > for obfuscated Pascal) The example fails in Delphi 6 btw, but works in FPC :-) Delphi does not allow low/high on sets (I vote to keep this FPC extension btw) ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] TShiftState as enum
> TShiftState is defined as TShiftState = set of (...); > > How can I iterate through the enums? If not, can we split and add an > enum: > > TShiftStateEnum = (...) > TShiftState = set of TShiftStateEnum; > > ? Of course that is possible. It requires some imagination though (and a feel for obfuscated Pascal) type myset = set of ( a1,a2,a3,a4,a5,a6); // workaround types const beginmyset=ord(low(myset)); endmyset=ord(high(myset)); type uglyenum = beginmyset..endmyset; uglyset= set of uglyenum; var b : myset; i : integer; begin b:=[a1,a2,a3]; for i:=ord(low(myset)) to ord(high(myset)) do if i in uglyset(b) then writeln(i); end. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
[fpc-devel] TShiftState as enum
TShiftState is defined as TShiftState = set of (...); How can I iterate through the enums? If not, can we split and add an enum: TShiftStateEnum = (...) TShiftState = set of TShiftStateEnum; ? Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel