From: Yannick Duchêne (Hibou57) on
Le Tue, 10 Aug 2010 16:03:13 +0200, Elias Salomão Helou Neto
<eshneto(a)gmail.com> a écrit:
> It is a pity that this post became a technical discussion on array
> indexing.
Could I, if you please, talk to Phil without your prior acknowledgment
please ? ;)

While I understand why you reacted (not the way you do... closed
parenthesis)

> A simple question that could be asked in a single line is:
> can Ada access arrays without range checking?
Sorry, due to a recent trouble with my news reader, I've the original post.

However, on this sentence basis, I would say: if you do not want range
check, then just disable it in the compiler option. But be warned you will
then be unable to catch runtime error. While there is a way to safely drop
this compiler option: validation with SPARK checker (just tell if you need
to learn about it).

If your matter is just about range checking, the answer is as simple as
that.

If you use GNAT, you may insert "-gnatp" in the command line arguments.
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Run_002dTime-Checks..html

If you use GNAT from the GPS environment, you may open the "Project" menu,
then the "Edit project properties" submenu. Then choose the "Switches"
tab, then the "Ada" tab and check the "Suppress all check" check box or
uncheck the "Overflow check" check box.

Providing I did not fail to understand what you meant.

--
There is even better than a pragma Assert: a SPARK --# check.
--# check C and WhoKnowWhat and YouKnowWho;
--# assert Ada;
-- i.e. forget about previous premises which leads to conclusion
-- and start with new conclusion as premise.
From: Shark8 on
On Aug 10, 7:52 am, Elias Salomão Helou Neto <eshn...(a)gmail.com>
wrote:

> > function Generic_Elliptic_Integral (X : Real; K : Real) return Real is
> > type Internal is digits Real'Digits * 2; -- You cannot do that!
> > begin
> > ...
>
> I don't fully understand the code, but it does seem to be very
> intuitive. What does
>
> type Real is digits <>;
>
> mean? Is "digits" a keyword of the language? I guess Ada groups
> fundamental types in categories and "digits" mean we must use some
> floating point type as the template argument, right? It sounds like a
> good idea, specially if things like that could be done for user
> defined types, i.e., if I can define my own type that "is digits <>".
>
> > --
> > Regards,
> > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de
>
>

"Digits" is a keyword in the language, in particular it is used to
define the number of digits-of-precision in a floating-point type. The
<> in this case is telling the compiler that the type 'Real', which is
the name some floating-point type will be referred to in the generic;
the purpose is to allow the programmer the ability to write code that
is independent of the precision but dependent on the [properties of
the] class of type.
From: Shark8 on
On Aug 10, 8:03 am, Elias Salomão Helou Neto <eshn...(a)gmail.com>
wrote:
> On Aug 10, 9:57 am, Yannick Duchêne (Hibou57)
>
>
>
> <yannick_duch...(a)yahoo.fr> wrote:
> > Le Tue, 10 Aug 2010 14:26:25 +0200, Phil Clayton  
> > <phil.clay...(a)lineone.net> a écrit:
>
> > >   A(A'Length - I - 1)
>
> > > (not valid Ada, of course.)
>
> > A(A'Last - (I - A'First))
>
> > > Perhaps "reverse" would be a better name for the operator "not" when
> > > the modulus is not a power of two?
>
> > Or "wrapped" ? But this would only make sens on an array instance basis,  
> > not on type basis. If the array actual range is not the same as the index  
> > type range, it fails. So this could not be a type primitive (operator).  
> > May be an array attribute ? A'From_Last ? A'Last_Based ?
>
> > "reverse" is already there for loop statements. I feel this makes for sens  
> > for loop, as what is reverse, is not the array index: this is the  
> > iteration which goes reversed order.
>
> > --
> > There is even better than a pragma Assert: a SPARK --# check.
> > --# check C and WhoKnowWhat and YouKnowWho;
> > --# assert Ada;
> > --  i.e. forget about previous premises which leads to conclusion
> > --  and start with new conclusion as premise.
>
> It is a pity that this post became a technical discussion on array
> indexing. A simple question that could be asked in a single line is:
> can Ada access arrays without range checking? My algorithm needs not
> wrapping, neither it needs range checking!
>
> Please, try avoiding pointless discussions on wrapped/non-wrapped
> types. Recall that I do not even know Ada's syntax, let alone its
> sophisticated type system. Your discussion can only possibly confuse
> me.
>
> Elias.

Yes, you can turn off run-time checking of array indecies.
Pragma Suppress is what you want; http://en.wikibooks.org/wiki/Ada_Programming/Pragmas/Suppress

The example given exactly answers your question:
My_Array : Array ( 1 .. 100 ) of Integer;
pragma Suppress( Index_Check );
...
Some_Variable := My_Array( 1000 ); -- Erroneous execution, here we
come!
From: Robert A Duff on
Elias Salom�o Helou Neto <eshneto(a)gmail.com> writes:

> does Ada allow me to do non range-checked access to arrays?

Yes. Pragma Suppress can be used to turn off some or all run-time
checks, locally or globally. As far as I know, all Ada compilers
have some way to do the same thing via compiler options
(command-line switches or whatever).

>> Ada has generics which are roughly same as templates. Unlikely to C+
>> generics are contracted and not automatically instantiated.
>
> What exactly does it mean? Is it something like run-time
> instantiation?

No, Ada generics work the same way as C++ templates -- the typical
implementation is that each instance gets a separate copy of
the code; instantiation happens at compile time. There is no
run-time instantiation.

"Contracted" above means that if the instantiation obeys the contract,
then you can't get any compilation errors in the body of the template.
For example, the generic says it wants a type with certain operations,
or with certain properties, and if the instance supplies such a type,
all is well.

"Not automatically instantiated" above means that each instantiation
of a generic appears explicitly in the code, as a separate
declaration.

> I don't fully understand the code, but it does seem to be very
> intuitive. What does
>
> type Real is digits <>;
>
> mean? Is "digits" a keyword of the language?

Yes. To declare a floating-point type:

type My_Float is digits 6;

And the compiler will pick some hardware type with at
least the requested precision. "My_Float'Digits" queries
the precision. Or:

type My_Float is digits 7 range 0.0 .. 1.0;

If you ask for more digits than are supported, the compiler
will complain.

The "digits <>" notation means this is a generic formal type,
and the instantiation should pass in an actual type that
is some floating-point type. Different instantiations might
pass different types with different 'Digits, and inside the
generic you can query it. In other words, the "<>" means
roughly "unknown".

If you try to pass a non-floating-point type to Real,
you will get a compile-time error.

- Bob
From: Yannick Duchêne (Hibou57) on
Le Tue, 10 Aug 2010 17:01:10 +0200, Robert A Duff
<bobduff(a)shell01.theworld.com> a écrit:
> No, Ada generics work the same way as C++ templates -- the typical
> implementation is that each instance gets a separate copy of
> the code
I wonder If I've understood you correctly. It seems Ada use code sharing
(which is the reason of some restriction on formal parameters). Code
duplication is the C++'s template way, not the Ada's generic package way..
Or am I mistaken somewhere ?