Recent

Author Topic: case of  (Read 12305 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #15 on: March 06, 2021, 07:35:27 pm »
Hi!

Nice trick for all situations where a set (again and again) is too small.

And

Code: Pascal  [Select][+][-]
  1. (w >= 10000) and (w<=20000)

is inconvenient.

Winni



winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #16 on: March 06, 2021, 09:36:40 pm »
Hi!

Question at the edge of this topic.

I can do

Code: Pascal  [Select][+][-]
  1. case frequency of
  2. 16..800: ...
  3. 801..2000: ...
  4. 2001..20000: ...
  5. end; //case
  6.  

So there is a set like mechanism for a range between 16 and 20000.
Why is the same mechanism not used for sets?

I know that old UCSD Pascal used the same mechanism for sets and case. Sets "only" for 0..4095 and case for 0..32767.

So why is fpc not going that way to enlargen sets?

Winni



Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: case of
« Reply #17 on: March 06, 2021, 09:51:44 pm »
[…] So why is fpc not going that way to enlargen sets?
Delhpi compatibility.

[…]
Code: Pascal  [Select][+][-]
  1. []
  2. class Operator TMyRangeType.in(A:Integer;B:TMyRangeType):Boolean;Inline;
  3. []
Well, “fun fact”: At one point something like 1337 in -42..5040 was possible.
Yours Sincerely
Kai Burghardt

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #18 on: March 06, 2021, 10:59:14 pm »
[…] So why is fpc not going that way to enlargen sets?
Delhpi compatibility.


Hi!

I know that "Delphi compatibility" is always the alibi for nearly every bug or restriction.
But this time not.

If you build a superset for the range of a set it does not disturb Delphi compatitbility, because a Delphi mini set would fit into a bigger fpc set. The other way round there might be problems. But this way is seldom.

And it might convince Delphi-Users to switch to  fpc/Lazarus.
( Or UCSD-Pascal).

The 256 element set restriction is a relict of Turbo Pascal and was already old fashioned in these days.

Winni

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: case of
« Reply #19 on: March 06, 2021, 11:50:03 pm »
I know that "Delphi compatibility" is always the alibi for nearly every bug or restriction.
But this time not.

If you build a superset for the range of a set it does not disturb Delphi compatitbility, […]
Well, then it isn’t so much about creating conflicts but there just were “more important” Delphi-compatibility-related things, so those were attended first, before creating something new, you know.
The 256 element set restriction is a relict of Turbo Pascal and was already old fashioned in these days.
I absolutely agree with you. The compiler and RTL do contain code for what’s called “Varset”. I understand the current default set implementations are “small set” and “normal set” in FPC terms.

I don’t know how to enable/use those “varset”. In revision 8515 Jonas wrote there were still problems, though.
Yours Sincerely
Kai Burghardt

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #20 on: March 07, 2021, 12:32:34 am »

I don’t know how to enable/use those “varset”. In revision 8515 Jonas wrote there were still problems, though.

Hi
Thanx  for that info.

Code: Text  [Select][+][-]
  1. Revision 8515 (13 years, 5 months ago)
  2.  


Ok. It just hit puberty and that is always a time of big changes.
So let's hope the best!

What else can I say????

Winni


PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: case of
« Reply #21 on: March 07, 2021, 02:48:34 pm »
I know that "Delphi compatibility" is always the alibi for nearly every bug or restriction.
But this time not.

If you build a superset for the range of a set it does not disturb Delphi compatitbility, […]
Well, then it isn’t so much about creating conflicts but there just were “more important” Delphi-compatibility-related things, so those were attended first, before creating something new, you know.

The problem is less Delphi-compatibility, but more size. If you have a set of 1024 elements you need 1024 bits aka 128 Byte aka an array of 32 UInt32. Of course one might argue that in today's time that is nothing, but one shouldn't scoff at that either.

That said I'd guess that we'll increase the limit of sets in one of the next major releases.

And case-statements have no restrictions regarding this.

The 256 element set restriction is a relict of Turbo Pascal and was already old fashioned in these days.
I absolutely agree with you. The compiler and RTL do contain code for what’s called “Varset”. I understand the current default set implementations are “small set” and “normal set” in FPC terms.

I don’t know how to enable/use those “varset”. In revision 8515 Jonas wrote there were still problems, though.

The varset helpers are used for any set with more than 32 elements as a bit array will be used for those instead of primitive types.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #22 on: March 07, 2021, 03:21:46 pm »

The problem is less Delphi-compatibility, but more size. If you have a set of 1024 elements you need 1024 bits aka 128 Byte aka an array of 32 UInt32. Of course one might argue that in today's time that is nothing, but one shouldn't scoff at that either.

That said I'd guess that we'll increase the limit of sets in one of the next major releases.


Hi!

Let's have a look at the Apple II and UCSD Pascal.
We had an OS that fitted in 64 kB (KILO!!).
We had segment procedures for swaping in  and out of the RAM to make a 250 kB executable to fit to that 64kB (for example Adimens DB).
We had two floppy drives and everything was awful slow.

BUT: We had sets for 4096 elements!
That was over 40 years ago!!

I hope the the next development step for sets will not only reach 1024 elements.
That would be only 1 / 4 of UCSD Pascal 40 years ago!

Winni

 

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: case of
« Reply #23 on: March 07, 2021, 03:28:47 pm »
Sets for more than 256 are listed in future plans since I remember: https://www.freepascal.org/future.html
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

avk

  • Hero Member
  • *****
  • Posts: 752
Re: case of
« Reply #24 on: March 07, 2021, 04:23:58 pm »
Hi!

@winni, I've already seen you regret about the lack of sets in FPC more than 256 elements several times.
Are you only interested in the built-in set, or is a home-made one suitable?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: case of
« Reply #25 on: March 07, 2021, 07:46:37 pm »
@avk

No - I am interestested in a built-in set  inside the fpc ≫ 256 elements.

A workaround with an array of set I made myself.

Winni

avk

  • Hero Member
  • *****
  • Posts: 752
Re: case of
« Reply #26 on: March 07, 2021, 08:01:03 pm »
The set, which I meant, almost completely mimics the built-in set and, moreover, can accept Subrange types, including those with a negative lower bound. But if no, then no.

flori

  • Full Member
  • ***
  • Posts: 196
Re: case of
« Reply #27 on: March 09, 2021, 12:09:00 pm »
Thank you everyone.
I managed to solve the problem

Code: Pascal  [Select][+][-]
  1. procedure TfrmLeaf.btnCalculateClick(Sender: TObject);
  2.  
  3.    // local functions visible inside the event method
  4.  
  5.   function IsEmpty(ATxt: TEdit): Boolean;
  6.   begin
  7.     Result := Length(Trim(ATxt.Text)) = 0;
  8.   end;
  9.  
  10.   function InRange(ALab, ALow, AHigh, AVH: TEdit): TValueRange;
  11.   begin
  12.     Result := vrNone;
  13.     if IsEmpty(ALab) or IsEmpty(ALow) or IsEmpty(AHigh) or IsEmpty(AVH) then
  14.       exit;
  15.     Result := vrMedium;
  16.     if Str2Float(ALab.Text) <= Str2Float(ALow.Text) then
  17.       Result := vrLow
  18.     else if Str2Float(ALab.Text) >= Str2Float(AHigh.Text) then
  19.       Result := vrHigh;
  20.   if Str2Float(ALab.Text) >= Str2Float(AVH.Text) then
  21.       Result := vvH;
  22.   end;
  23.  
  24.   procedure ClassifyRange(Range: TValueRange; Res: TEdit);
  25.   begin
  26.      case Range of
  27.        vrNone: begin Res.Text := '-none-'; Res.Color := clDefault end;
  28.        vrLow: begin Res.Text := 'Low'; Res.Color := $00D9FFCC end;
  29.        vrMedium: begin Res.Text := 'Medium'; Res.Color := $00FFC8C8 end;
  30.        vrHigh: begin Res.Text:= 'High'; Res.Color := $00B9B9FF end;
  31.        vvH: begin Res.Text:= 'Very High'; Res.Color := $00B9B9FF end;
  32.      end;
  33.   end;
  34.  
  35. begin
  36.   // calculate event
  37.   ClassifyRange(InRange(N_Lab,N_Low,N_High,Nvery),N_Res);
  38.   ClassifyRange(InRange(P_Lab,P_Low,P_High,Pvery),P_Res);
  39.   ClassifyRange(InRange(K_Lab,K_Low,K_High,Kvery),K_Res);

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
Re: case of
« Reply #28 on: March 09, 2021, 03:09:50 pm »
@winni, I've already seen you regret about the lack of sets in FPC more than 256 elements several times.
Are you only interested in the built-in set, or is a home-made one suitable?

Hello! For me, if you have a code to share, I would take it.  :)

Regards.

Roland
My projects are on Gitlab and on Codeberg.

avk

  • Hero Member
  • *****
  • Posts: 752
Re: case of
« Reply #29 on: March 09, 2021, 04:05:27 pm »
This set(TGSet) is part of a fairly large unit within the package, but the good news is that this unit is self-sufficient and the TGSet itself depends on the minimum set of functionality of this unit. Thus, it is easy to make TGSet self-contained and the license does not prevent you from doing this.

UPD:  if you have any problems, let me know.
« Last Edit: March 09, 2021, 07:01:29 pm by avk »

 

TinyPortal © 2005-2018