• Implicit_Dereference for Real_Vectors ?

    From Jim Paloander@21:1/5 to All on Sun Jan 22 13:52:36 2023
    Dear ADA experts,
    is it possible to extend an inherent ADA package such Real_Arrays with something like this?

    type Accessor (Data: not null access Real_Vector) is limited private with Implicit_Dereference => Data;

    In the hope that I could somehow declare:
    A: Accessor := new Real_Vector ( 1 .. N );
    B: Accessor := new Real_Vector ( 1 .. N );
    X: Accessor := new Real_Vector ( 1 .. N );

    So I could write a statement:
    X := A + B;
    instead of
    X.all := A.all + B.all;
    since I am forced to use heap allocation for N > 100,000? Sorry for my ignorance but I am new to ADA and I cannot find enough documentation. Containers seem to be awful in terms of syntax for mathematical programming and linear algebra, and the fact
    that Real_Arrays allow clean syntax for operator overloading only if allocated on the limited stack is really extremely frustrating. I totally understand the preference for stack over heap for certain applications, but for the applications I have in
    mind the size of the problem is determined at runtime. There is no way to know it in advance. I tried -D1000m -d1000m in the binder options to no avail. Always I get the STACK_OVERFLOW error. My only option is heap. Moreover, I would expect that ADA's
    Numerics are as efficient as Fortran's overloaded operators and no temporary objects are generated when you do something like:
    X := A + B + C + A + B;

    Unfortunately ADA introduces a temporary for every addition that is added to the next creating a 2nd temporary and so on.
    temp1 := A+B; temp2 := C+temp1; temp3 := B+temp2; temp4 := A+temp3; X := temp4;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)