News for hackers. Stuff that matters.
Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @03:54PM (#26320545)
And, even better, arrays in Ada (can't speak to Pascal) can be any discrete type so long as it is a range:

  type Character_Histogram is Array (range 'A'..'Z') of Integer;
  -- syntax may be off, not enough practice to do this cold right now
Re:Giving Ada a Chance by FpUser on Tuesday March 02, 2021 @04:08PM (#26320773)

  type
    TPerson = record
      name: string;
      age: integer;
    end;
    TThrteenPersons = array[10..22] of TPerson;

  procedure Check(const aPerson: TPerson);
  var
    vPerson: TThrteenPersons;
  begin
    vPerson[11] := aPerson; // this is ok
    vPerson[1] := aPerson; // this one gives compile error
  end;
alternatively if runtime range checking is on then vPerson[i] = aPerson will raise the exception if i is out of range
Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @04:12PM (#26320831)
Right. I know it works with numeric indexes in Pascal. My point was that (using my previous example) in Ada it works with any discrete type, in that case characters (which are not numbers in disguise in Ada) so I can do this:

  Histogram : Character_Histogram;
  ...
  Histogram['A'] := Histogram['A'] + 1;
(Ok, a bit more work because I didn't initialize the histogram to 0.)
Re:Giving Ada a Chance by kwhitefoot on Tuesday March 02, 2021 @05:26PM (#26321929)
It works with any ordinal type in Pascal, including characters, booleans and enums.
Re:Giving Ada a Chance by Lucretia9 on Tuesday March 02, 2021 @04:56PM (#26321512)
Square brackets are coming, so you'd have to use ('A')
Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @05:40PM (#26322111)
Hah, I've been in Go lately so my brain defaulted to the wrong thing in that example.
Re:Giving Ada a Chance by FpUser on Tuesday March 02, 2021 @05:25PM (#26321910)
Pascal (well Delphi/FreePascal incarnation) also works with chars and enums.

This modern pascal is very feature rich and has plenty of fancy bells and whistles.

Re:Giving Ada a Chance by drfuchs on Tuesday March 02, 2021 @05:39PM (#26322106)
Wirth's original, standard Pascal allowed for int/char/bool/enum, and ranges thereof, as array bounds; it wasn't a Delphi enhancement.
Re:Giving Ada a Chance by FpUser on Tuesday March 02, 2021 @05:48PM (#26322204)
I am sure it was. I am just not familiar with it hence specified the one I know.
Re:Giving Ada a Chance by kwhitefoot on Tuesday March 02, 2021 @05:24PM (#26321888)
In Pascal you can use any ordinal type as the type of the array index. You can create a new type from a range of ordinal values.

So you can have arrays where the index runs from -10 to +20 or from +7 to +26 for instance. Booleans are also ordinal types so you can have an array where the index is boolean.

Re:Giving Ada a Chance by Avshalom on Tuesday March 02, 2021 @03:59PM (#26320634)
I don't think it even needs to be a range, you can index using enums
Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @04:06PM (#26320732)
Well, "range" was not the correct term. What I meant is that you can't treat the source as sparse. You can't skip portions of it. So you can't make an array that only covers every other element of this enumeration:

  type Colors is (Red, Green, Blue, Black, Gray, White);
It has to be a consecutive group of them, taken in order, as the specification of even this enumeration has an ordering to it as far as Ada is concerned. So I can make an array using all of Colors as the index, or some subset but it has to be, say, Red..Blue and not Red|Blue skipping over Green.
Re:Giving Ada a Chance by Lucretia9 on Tuesday March 02, 2021 @04:55PM (#26321503)
Ada 2012 allows you to define gaps, this is my best example I have available https://github.com/Lucretia/sdlada/blob/master/src/sdl-video...
Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @05:43PM (#26322152)
That is great to read, and probably a sign that my learning materials should be updated. I'll try to remember this in the future.