Recent

Author Topic: Sets Vs Arrays. When to use and why.  (Read 1787 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5935
  • Compiler Developer
Re: Sets Vs Arrays. When to use and why.
« Reply #15 on: March 11, 2025, 09:18:26 pm »
On a completely different note, it would be nice if FPC allowed array ranges to be specified using gapless enumerations that do not start at zero.

One could indeed argue that this would make sense considering that both arrays with enum indices and arrays not starting at 0... 🤔

Another nice improvement would be for FPC to allow using "with" to specify enumeration scopes.

What have you in mind here?

440bx

  • Hero Member
  • *****
  • Posts: 5137
Re: Sets Vs Arrays. When to use and why.
« Reply #16 on: March 12, 2025, 03:11:08 am »
Another nice improvement would be for FPC to allow using "with" to specify enumeration scopes.

What have you in mind here?
What I have in mind is that when enumerations are scoped then the enumeration identifier should be allowed in a "with" statement since a "with" specifies a scope.  e.g, (and presuming scoped enums are on):
Code: Pascal  [Select][+][-]
  1. var
  2.   SomeSet : set of scoped_enum_identifier;
  3.  
  4. begin
  5.   ..
  6.   { this  (note: begin/end present for aesthetic purposes only) }
  7.  
  8.   with <scoped_enum_identifier> do
  9.   begin
  10.     SomeSet := [enum_element_a,
  11.                 enum_element_b,
  12.                 enum_element_n];
  13.   end;
  14.  
  15.   { instead of (as currently required) }
  16.  
  17.     SomeSet := [scoped_enum_identifier.enum_element_a,
  18.                 scoped_enum_identifier.enum_element_b,
  19.                 scoped_enum_identifier.enum_element_n];
  20. end;
  21.  
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5935
  • Compiler Developer
Re: Sets Vs Arrays. When to use and why.
« Reply #17 on: March 14, 2025, 08:13:37 pm »
Another nice improvement would be for FPC to allow using "with" to specify enumeration scopes.

What have you in mind here?
What I have in mind is that when enumerations are scoped then the enumeration identifier should be allowed in a "with" statement since a "with" specifies a scope.  e.g, (and presuming scoped enums are on):

Ah. That is indeed something one could think about... 🤔 Maybe you want to file a feature request so that it's not forgotten?

440bx

  • Hero Member
  • *****
  • Posts: 5137
Re: Sets Vs Arrays. When to use and why.
« Reply #18 on: March 14, 2025, 08:46:06 pm »
Ah. That is indeed something one could think about... 🤔 Maybe you want to file a feature request so that it's not forgotten?
Done.

issue/request: 41191
link: https://gitlab.com/freepascal.org/fpc/source/-/issues/41191
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

TBMan

  • Full Member
  • ***
  • Posts: 114
Re: Sets Vs Arrays. When to use and why.
« Reply #19 on: March 15, 2025, 12:18:00 am »
I've used a set when I want to get a keyboard response and I want to restrict it:

Code: Pascal  [Select][+][-]
  1. GoodInput : set of char = ['1','2','3','4','5','6','7','8','9']

PascalDragon

  • Hero Member
  • *****
  • Posts: 5935
  • Compiler Developer
Re: Sets Vs Arrays. When to use and why.
« Reply #20 on: March 18, 2025, 08:50:22 pm »
Ah. That is indeed something one could think about... 🤔 Maybe you want to file a feature request so that it's not forgotten?
Done.

issue/request: 41191
link: https://gitlab.com/freepascal.org/fpc/source/-/issues/41191

Thank you :)

440bx

  • Hero Member
  • *****
  • Posts: 5137
Re: Sets Vs Arrays. When to use and why.
« Reply #21 on: March 18, 2025, 08:57:02 pm »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018