-----Original Message----- From: Marco van de Voort
Sent: Friday, December 23, 2011 13:21
To: FPC developers' list
Subject: Re: [fpc-devel] Limitations of static "ranged" integer typesandsucc/pred, and dynamic solution.

In our previous episode, Skybuck Flying said:

Currently there simply is no dynamic/runtime version of it.

"
You are totally right. Please submit a patch for conforming arrays support
:-)
"

Glad you agree, now we can discuss possible solutions ;) :)

First a solution has to be found, possible solutions could be:

TRangedInteger = record
   Low : integer;
   High : integer;
   Value : integer;
end;

or perhaps just a range or perhaps both.

TRange = record
   Low : integer;
   High : integer;
end;

And then perhaps some checks/runtime checks can be build in by the compiler.

Alternatively perhaps assignment operation, increment operator and other operators could be overloaded to do the necessary range checking ;)

I am not sure what Low/High/Succ/Pred do ? Do they ever throw an runtime error, or exception ?

Perhaps just having a constructor would already be enough to just solve the loop:

var
  vIndex : TRangedInteger;
  vValue : TRangedInteger; // problem, need to set range again :(
begin
  vIndex := TRangedInteger.Create( -Random(100), Random(100) );
vValue := TRangedInteger.Create( vIndex ); // perhaps could be solved with a copy from the other.

  // would be more nice if it was like a dynamic type or so ;)
vRange := TRangedInteger.Create( 0, AskUserForMax ); // ask user for values
  vIndex := TRangedInteger.Create( vRange );
  vValue := TRangedInteger.Create( vRange );

  for vIndex := vIndex.Low to vIndex.High do
  begin
      if vValue = vValue.High then
      begin
          vValue.Low;
      end else
      begin
         vValue := vValue.Succ;
      end;
  end;
end;

So you see coming up with a solution wasn't that hard, however this is still a somewhat half-baked solution.

It would be nice if simply Low(vValue) and High(vValue) could be used, so static (compile-time)and dynamic code (run-time) looks the same and can be compiled without code changes.

So somehow Low and High would need to be "attached" to the runtime type: TRangedInteger.

Perhaps Low and High and Succ and Pred should become "operators" ? For record ?!?

So that they can be overriden ?

Bye,
 Skybuck.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to