Re: Data table text I/O package?



Marius Amado Alves <amado.alves@xxxxxxxxxx> writes:

> Yes. This is interesting, useful, and easy. From the header you get the
> field names, from the first data line with deduce the data types. With
> these elements you can generate the record type and procedures to read
> the file.

Hmm. Interesting idea. But you will lose the full power of Ada's type
system. You cannot, in general, deduce the type from the data, in Ada.
I mean, 123 could be any integer type, and a typical Ada program has
many integer types.

For that matter, how do you know 123 is not intended to be Type_String,
in your example below?

>... A trick I often use to deduce data types is based on 'Value:

I believe this trick will run afoul of RM-11.6. It probably works in
practise, but I think that an implementation is allowed to return
Type_Float, no matter what string you pass to Value!

Did I mention that I don't like 11.6? ;-)

> function Get_Type (Value : String) return Data_Type is
> F : Float;
> I : Integer;
> begin
> F := Float'Value (Value);
> return Type_Float;
> exception
> when Constraint_Error =>
> begin
> I := Integer'Value (Value);
> return Type_Integer;
> exception
> when Constraint_Error =>
> return Type_String;
> end;
> end;

- Bob
.



Relevant Pages

  • Re: Decimal rounding function
    ... In other words, is there a sane ... for that matter) way that can be implemented ... double is the best integer type. ... Note that multiplications and divisions need to be scaled. ...
    (comp.lang.c)
  • error 80070002; says cannot find specified file
    ... Does it matter that the user does not have a sound card? ... If anymore info is needed to deduce a possible solution let me know. ...
    (microsoft.public.windowsmedia.player)
  • Re: quick question about memset
    ... > that matter) might make a trap representation, ... object of integer type to all-bits-zero sets it to value zero. ...
    (comp.lang.c)