comp.lang.ada
 help / color / mirror / Atom feed
* gnat.string_split , howto manipulate slice numbers
@ 2019-10-29  1:54 Alain De Vos
  2019-10-29  8:17 ` briot.emmanuel
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Alain De Vos @ 2019-10-29  1:54 UTC (permalink / raw)


I have a String_Split.Slice_Number , but I need the number before.
...
J := String_Split.Slice_Count (Lines);
for I in 2 .. J loop
...
This works but ,
...
J := String_Split.Slice_Count (Lines) - 1 ;
for I in 2 .. J loop
...
This does not work.
Error :
lsblk.adb:91:44: operator for type "Slice_Number" defined at g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  1:54 gnat.string_split , howto manipulate slice numbers Alain De Vos
@ 2019-10-29  8:17 ` briot.emmanuel
  2019-10-29 16:56   ` Jeffrey R. Carter
  2019-10-29 23:36   ` Stephen Leake
  2019-10-29  8:35 ` Simon Wright
  2019-10-29 16:53 ` Jeffrey R. Carter
  2 siblings, 2 replies; 21+ messages in thread
From: briot.emmanuel @ 2019-10-29  8:17 UTC (permalink / raw)


> This does not work.
> Error :
> lsblk.adb:91:44: operator for type "Slice_Number" defined at g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible

You need to make operators for the type visible.
Either with:

    use type GNAT.String_Split.Slice_Number;

or 
    use GNAT.String_Split;



You might want to take a look at GNATCOLL.Strings (also distributed by AdaCore, and generally installed with the compiler nowadays), which provides services similar to Ada.Strings.Unbounded but also has a split operation.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  1:54 gnat.string_split , howto manipulate slice numbers Alain De Vos
  2019-10-29  8:17 ` briot.emmanuel
@ 2019-10-29  8:35 ` Simon Wright
  2019-10-29 11:08   ` Alain De Vos
  2019-10-29 16:41   ` Simon Wright
  2019-10-29 16:53 ` Jeffrey R. Carter
  2 siblings, 2 replies; 21+ messages in thread
From: Simon Wright @ 2019-10-29  8:35 UTC (permalink / raw)


Alain De Vos <devosalain71@gmail.com> writes:

> I have a String_Split.Slice_Number , but I need the number before.
> ...
> J := String_Split.Slice_Count (Lines);
> for I in 2 .. J loop
> ...
> This works but ,
> ...
> J := String_Split.Slice_Count (Lines) - 1 ;
> for I in 2 .. J loop
> ...
> This does not work.
> Error :
> lsblk.adb:91:44: operator for type "Slice_Number" defined at
> g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible

The error message says that there is an operator "-" for Slice_Number,
but it needs to be made directly visible; either "use String_Split", or
"use type String_Split.Slice_Count".

However! clearly Lines is of some numeric type (Natural?) defined
earlier, for which operator "-" is visible. So use that operator
instead, by applying it before the conversion:

   J := String_Split.Slice_Count (Lines - 1);


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  8:35 ` Simon Wright
@ 2019-10-29 11:08   ` Alain De Vos
  2019-10-29 11:20     ` Alain De Vos
  2019-10-29 16:41   ` Simon Wright
  1 sibling, 1 reply; 21+ messages in thread
From: Alain De Vos @ 2019-10-29 11:08 UTC (permalink / raw)


On Tuesday, October 29, 2019 at 9:35:31 AM UTC+1, Simon Wright wrote:
> Alain De Vos <devosalain71@gmail.com> writes:
> 
> > I have a String_Split.Slice_Number , but I need the number before.
> > ...
> > J := String_Split.Slice_Count (Lines);
> > for I in 2 .. J loop
> > ...
> > This works but ,
> > ...
> > J := String_Split.Slice_Count (Lines) - 1 ;
> > for I in 2 .. J loop
> > ...
> > This does not work.
> > Error :
> > lsblk.adb:91:44: operator for type "Slice_Number" defined at
> > g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible
> 
> The error message says that there is an operator "-" for Slice_Number,
> but it needs to be made directly visible; either "use String_Split", or
> "use type String_Split.Slice_Count".
> 
> However! clearly Lines is of some numeric type (Natural?) defined
> earlier, for which operator "-" is visible. So use that operator
> instead, by applying it before the conversion:
> 
>    J := String_Split.Slice_Count (Lines - 1);

Lines is of type ,

Lines : String_Split.Slice_Set;


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 11:08   ` Alain De Vos
@ 2019-10-29 11:20     ` Alain De Vos
  2019-10-29 16:44       ` J-P. Rosen
  2019-10-29 16:47       ` Simon Wright
  0 siblings, 2 replies; 21+ messages in thread
From: Alain De Vos @ 2019-10-29 11:20 UTC (permalink / raw)


On Tuesday, October 29, 2019 at 12:08:12 PM UTC+1, Alain De Vos wrote:
> On Tuesday, October 29, 2019 at 9:35:31 AM UTC+1, Simon Wright wrote:
> > Alain De Vos <devosalain71@gmail.com> writes:
> > 
> > > I have a String_Split.Slice_Number , but I need the number before.
> > > ...
> > > J := String_Split.Slice_Count (Lines);
> > > for I in 2 .. J loop
> > > ...
> > > This works but ,
> > > ...
> > > J := String_Split.Slice_Count (Lines) - 1 ;
> > > for I in 2 .. J loop
> > > ...
> > > This does not work.
> > > Error :
> > > lsblk.adb:91:44: operator for type "Slice_Number" defined at
> > > g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible
> > 
> > The error message says that there is an operator "-" for Slice_Number,
> > but it needs to be made directly visible; either "use String_Split", or
> > "use type String_Split.Slice_Count".
> > 
> > However! clearly Lines is of some numeric type (Natural?) defined
> > earlier, for which operator "-" is visible. So use that operator
> > instead, by applying it before the conversion:
> > 
> >    J := String_Split.Slice_Count (Lines - 1);
> 
> Lines is of type ,
> 
> Lines : String_Split.Slice_Set;

-------------------------------------------------
I tested and the addition of ,
use type GNAT.String_Split.Slice_Number; 
fixed it.
I looks like without it the operator - is not understood.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  8:35 ` Simon Wright
  2019-10-29 11:08   ` Alain De Vos
@ 2019-10-29 16:41   ` Simon Wright
  1 sibling, 0 replies; 21+ messages in thread
From: Simon Wright @ 2019-10-29 16:41 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> "use type String_Split.Slice_Count"

use type String_Split.Slice_Number

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 11:20     ` Alain De Vos
@ 2019-10-29 16:44       ` J-P. Rosen
  2019-10-29 16:47       ` Simon Wright
  1 sibling, 0 replies; 21+ messages in thread
From: J-P. Rosen @ 2019-10-29 16:44 UTC (permalink / raw)


Le 29/10/2019 à 12:20, Alain De Vos a écrit :
> I tested and the addition of ,
> use type GNAT.String_Split.Slice_Number; 
> fixed it.
> I looks like without it the operator - is not understood.
It's not that it is not "understood", it just isn't visible.

Unlike many languages, Ada has a very uniform view and little magic. "-"
is just a function, which is automatically declared where the type it
operates on is declared. Like anything else, you can use it if and only
if it is visible. Use clauses, use type clauses, or dot notation are
different ways of making things visible, depending how wide you want to
open the visibility window.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 11:20     ` Alain De Vos
  2019-10-29 16:44       ` J-P. Rosen
@ 2019-10-29 16:47       ` Simon Wright
  2019-10-29 18:33         ` J-P. Rosen
  1 sibling, 1 reply; 21+ messages in thread
From: Simon Wright @ 2019-10-29 16:47 UTC (permalink / raw)


Alain De Vos <devosalain71@gmail.com> writes:

> I tested and the addition of ,
> use type GNAT.String_Split.Slice_Number; 
> fixed it.
> I looks like without it the operator - is not understood.

Yes:

   type Slice_Number is new Natural;

For me, this carries declaring a type rather than a subtype further than
necessary. A subtype? Or why not just use Natural?


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  1:54 gnat.string_split , howto manipulate slice numbers Alain De Vos
  2019-10-29  8:17 ` briot.emmanuel
  2019-10-29  8:35 ` Simon Wright
@ 2019-10-29 16:53 ` Jeffrey R. Carter
  2 siblings, 0 replies; 21+ messages in thread
From: Jeffrey R. Carter @ 2019-10-29 16:53 UTC (permalink / raw)


On 10/29/19 2:54 AM, Alain De Vos wrote:
> lsblk.adb:91:44: operator for type "Slice_Number" defined at g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible

As the error message indicates, this is a visibility problem. Understanding 
visibility is key to understanding Ada. Since it's clear you don't understand 
visibility yet, I suggest you read /Ada Distilled/

https://www.adaic.org/wp-content/uploads/2010/05/Ada-Distilled-24-January-2011-Ada-2005-Version.pdf

Yes, it's for ISO/IEC 8652:2007, but visibility is still much the same.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  8:17 ` briot.emmanuel
@ 2019-10-29 16:56   ` Jeffrey R. Carter
  2019-10-29 19:36     ` Niklas Holsti
  2019-10-29 23:36   ` Stephen Leake
  1 sibling, 1 reply; 21+ messages in thread
From: Jeffrey R. Carter @ 2019-10-29 16:56 UTC (permalink / raw)


On 10/29/19 9:17 AM, briot.emmanuel@gmail.com wrote:
> 
>      use type GNAT.String_Split.Slice_Number;
> 
> or
>      use GNAT.String_Split;

or

function "-" (Left  : GNAT.String_Split.Slice_Number;
               Right : GNAT.String_Split.Slice_Number)
return GNAT.String_Split.Slice_Number renames GNAT.String_Split."-";

or

GNAT.String_Split."-" (Left, Right)

There are more ways to get around lack of visibility than just use clauses.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 16:47       ` Simon Wright
@ 2019-10-29 18:33         ` J-P. Rosen
  2019-10-29 19:37           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 21+ messages in thread
From: J-P. Rosen @ 2019-10-29 18:33 UTC (permalink / raw)


Le 29/10/2019 à 17:47, Simon Wright a écrit :
>    type Slice_Number is new Natural;
> 
> For me, this carries declaring a type rather than a subtype further than
> necessary. A subtype? Or why not just use Natural?
Integer (or its subtypes) should be avoided in general. It is non
portable, and carries no information to the reader about the purpose of
the type. Making appropriate types that cannot be mixed is key to the
philosophy of Ada ("strong typing", you know...).

Of course, defining proper bounds is better than deriving from Integer,
but in reusable components, you don't always have enough context to
determine absolute bounds, so you have to rely on a "reasonable" integer
type like Integer.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 16:56   ` Jeffrey R. Carter
@ 2019-10-29 19:36     ` Niklas Holsti
  2019-10-29 23:06       ` J-P. Rosen
  0 siblings, 1 reply; 21+ messages in thread
From: Niklas Holsti @ 2019-10-29 19:36 UTC (permalink / raw)


On 2019-10-29 18:56, Jeffrey R. Carter wrote:
> On 10/29/19 9:17 AM, briot.emmanuel@gmail.com wrote:
>>
>>      use type GNAT.String_Split.Slice_Number;
>>
>> or
>>      use GNAT.String_Split;
> 
> or
> 
> function "-" (Left  : GNAT.String_Split.Slice_Number;
>                Right : GNAT.String_Split.Slice_Number)
> return GNAT.String_Split.Slice_Number renames GNAT.String_Split."-";

Yes, but I do not recommend this "rename" method for wide use. Some 
decades ago, in an Ada 83 project which thus did not allow "use type", 
we had several bugs where copy-paste sloppiness resulted in (for 
example) some "-" operator renaming a "+" operator, with "amusing" results.

I believe the risk of such bugs was a major reason for the introduction 
of "use type" in Ada.

--
Niklas Holsti
niklas holsti tidorum fi
       .      @       .


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 18:33         ` J-P. Rosen
@ 2019-10-29 19:37           ` Dmitry A. Kazakov
  2019-10-30 11:30             ` Simon Wright
  0 siblings, 1 reply; 21+ messages in thread
From: Dmitry A. Kazakov @ 2019-10-29 19:37 UTC (permalink / raw)


On 2019-10-29 19:33, J-P. Rosen wrote:
> Le 29/10/2019 à 17:47, Simon Wright a écrit :
>>     type Slice_Number is new Natural;
>>
>> For me, this carries declaring a type rather than a subtype further than
>> necessary. A subtype? Or why not just use Natural?
> Integer (or its subtypes) should be avoided in general. It is non
> portable, and carries no information to the reader about the purpose of
> the type. Making appropriate types that cannot be mixed is key to the
> philosophy of Ada ("strong typing", you know...).

Another reason is to distinguish index/key from position. When both are 
subtypes of integer some bugs may slip through, e.g.

    A (A'Length - 1)

This is broken code, but the compiler cannot detect it.

Or when you instantiate a generic container:

generic
    type Position_Type is range <>;
    type Index_Type is private;
    type Element_Type is private;
package Generic_Container is
    ...
    function Get (Container : Container_Type; Position : Position_Type)
       return Element_Type;
    function Get (Container : Container_Type; Key : Key_Type)
       return Element_Type;

It fails when instantiated with subtypes of same integer type.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 19:36     ` Niklas Holsti
@ 2019-10-29 23:06       ` J-P. Rosen
  2019-11-01  9:45         ` joakimds
  0 siblings, 1 reply; 21+ messages in thread
From: J-P. Rosen @ 2019-10-29 23:06 UTC (permalink / raw)


Le 29/10/2019 à 20:36, Niklas Holsti a écrit :
> Yes, but I do not recommend this "rename" method for wide use. Some
> decades ago, in an Ada 83 project which thus did not allow "use type",
> we had several bugs where copy-paste sloppiness resulted in (for
> example) some "-" operator renaming a "+" operator, with "amusing" results.
[Yet another shameless plug] AdaControl has a rule to check renamings
with different names (precisely intended for eliminate this error)

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29  8:17 ` briot.emmanuel
  2019-10-29 16:56   ` Jeffrey R. Carter
@ 2019-10-29 23:36   ` Stephen Leake
  1 sibling, 0 replies; 21+ messages in thread
From: Stephen Leake @ 2019-10-29 23:36 UTC (permalink / raw)


On Tuesday, October 29, 2019 at 1:17:54 AM UTC-7, briot....@gmail.com wrote:
> > This does not work.
> > Error :
> > lsblk.adb:91:44: operator for type "Slice_Number" defined at g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible
> 
> You need to make operators for the type visible.
> Either with:
> 
>     use type GNAT.String_Split.Slice_Number;
> 
> or 
>     use GNAT.String_Split;

In Emacs, C-c M-` (ada-fix-compiler-error) will insert the "use type" option for you.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 19:37           ` Dmitry A. Kazakov
@ 2019-10-30 11:30             ` Simon Wright
  2019-10-31  9:30               ` joakimds
  2019-10-31 10:12               ` Dmitry A. Kazakov
  0 siblings, 2 replies; 21+ messages in thread
From: Simon Wright @ 2019-10-30 11:30 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2019-10-29 19:33, J-P. Rosen wrote:
>> Le 29/10/2019 à 17:47, Simon Wright a écrit :
>>>     type Slice_Number is new Natural;
>>>
>>> For me, this carries declaring a type rather than a subtype further than
>>> necessary. A subtype? Or why not just use Natural?
>> Integer (or its subtypes) should be avoided in general. It is non
>> portable, and carries no information to the reader about the purpose of
>> the type. Making appropriate types that cannot be mixed is key to the
>> philosophy of Ada ("strong typing", you know...).
>
> Another reason is to distinguish index/key from position. When both
> are subtypes of integer some bugs may slip through, e.g.
>
>    A (A'Length - 1)
>
> This is broken code, but the compiler cannot detect it.

How is it broken?

> Or when you instantiate a generic container:
>
> generic
>    type Position_Type is range <>;
>    type Index_Type is private;
>    type Element_Type is private;
> package Generic_Container is
>    ...
>    function Get (Container : Container_Type; Position : Position_Type)
>       return Element_Type;
>    function Get (Container : Container_Type; Key : Key_Type)
>       return Element_Type;
>
> It fails when instantiated with subtypes of same integer type.

Again.You'd need to use named parameter association, but otherwise, what
am I missing?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-30 11:30             ` Simon Wright
@ 2019-10-31  9:30               ` joakimds
  2019-10-31 10:12               ` Dmitry A. Kazakov
  1 sibling, 0 replies; 21+ messages in thread
From: joakimds @ 2019-10-31  9:30 UTC (permalink / raw)


> >
> > Another reason is to distinguish index/key from position. When both
> > are subtypes of integer some bugs may slip through, e.g.
> >
> >    A (A'Length - 1)
> >
> > This is broken code, but the compiler cannot detect it.
> 
> How is it broken?
> 

The index should be an index from A'First to A'Last and using A'Length does not guarantee A'Length - 1 being a valid index. Hmm... how to fix it in the best possible way? Or just accept it being an edge case Ada does not detect at compile-time?

Best regards,
Joakim

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-30 11:30             ` Simon Wright
  2019-10-31  9:30               ` joakimds
@ 2019-10-31 10:12               ` Dmitry A. Kazakov
  2019-10-31 18:36                 ` J-P. Rosen
  1 sibling, 1 reply; 21+ messages in thread
From: Dmitry A. Kazakov @ 2019-10-31 10:12 UTC (permalink / raw)


On 2019-10-30 12:30, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On 2019-10-29 19:33, J-P. Rosen wrote:
>>> Le 29/10/2019 à 17:47, Simon Wright a écrit :
>>>>      type Slice_Number is new Natural;
>>>>
>>>> For me, this carries declaring a type rather than a subtype further than
>>>> necessary. A subtype? Or why not just use Natural?
>>> Integer (or its subtypes) should be avoided in general. It is non
>>> portable, and carries no information to the reader about the purpose of
>>> the type. Making appropriate types that cannot be mixed is key to the
>>> philosophy of Ada ("strong typing", you know...).
>>
>> Another reason is to distinguish index/key from position. When both
>> are subtypes of integer some bugs may slip through, e.g.
>>
>>     A (A'Length - 1)
>>
>> This is broken code, but the compiler cannot detect it.
> 
> How is it broken?

It should have been

    A (A'Last - 1)

A'Length is position/offset, only occasionally numerically equal to index.

Compare it with Time and Duration. These are two distinct types. Array 
index is like Time. Array length is like Duration, a difference between 
two Times.

BTW, here come further issues why indexing by integer types is not so 
good idea from the strong typing point of view. Arithmetic on indices 
does not make sense, like adding or multiplying times does not. Except 
some rare cases of low-level programming index arithmetic is an error.

If Ada had a more powerful type system one would not only declare a new 
index type as J-P suggested, but also make sure the arithmetic would  be 
replaced with this:

    function "-" (Left, Right : Index_Type)
       return Universal_Integer;
    function "-" (Left : Index_Type; Right : Universal_Integer)
       return Index_Type;
    function "-" (Left : Universal_Integer; Right : Index_Type)
       return Index_Type;
    function "+" (Left : Universal_Integer; Right : Index_Type)
       return Index_Type;
    function "+" (Left : Index_Type; Right : Universal_Integer)
       return Index_Type;

>> Or when you instantiate a generic container:
>>
>> generic
>>     type Position_Type is range <>;
>>     type Index_Type is private;
>>     type Element_Type is private;
>> package Generic_Container is
>>     ...
>>     function Get (Container : Container_Type; Position : Position_Type)
>>        return Element_Type;
>>     function Get (Container : Container_Type; Key : Key_Type)
>>        return Element_Type;
>>
>> It fails when instantiated with subtypes of same integer type.
> 
> Again.You'd need to use named parameter association, but otherwise, what
> am I missing?

The problem is with Get. When you instantiate Generic_Container like:

    package Oops is new Generic_Container (Positive, Integer, Float);

Then two declarations of Get will collide. [Ada generics are only weakly 
typed]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-31 10:12               ` Dmitry A. Kazakov
@ 2019-10-31 18:36                 ` J-P. Rosen
  2019-11-01  9:39                   ` joakimds
  0 siblings, 1 reply; 21+ messages in thread
From: J-P. Rosen @ 2019-10-31 18:36 UTC (permalink / raw)


Le 31/10/2019 à 11:12, Dmitry A. Kazakov a écrit :
> BTW, here come further issues why indexing by integer types is not so
> good idea from the strong typing point of view. Arithmetic on indices
> does not make sense, like adding or multiplying times does not. Except
> some rare cases of low-level programming index arithmetic is an error.
you can even declare:
function "*" (L, R : T) return T is abstract;

and thus forbid the use of multiplication when it does not make sense.

Most programming languages praise what they allow to do; Ada is the only
language that praises what it prevents from doing!

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-31 18:36                 ` J-P. Rosen
@ 2019-11-01  9:39                   ` joakimds
  0 siblings, 0 replies; 21+ messages in thread
From: joakimds @ 2019-11-01  9:39 UTC (permalink / raw)


> you can even declare:
> function "*" (L, R : T) return T is abstract;
> 
> and thus forbid the use of multiplication when it does not make sense.
> 
> Most programming languages praise what they allow to do; Ada is the only
> language that praises what it prevents from doing!
> 
> -- 
> J-P. Rosen
> Adalog
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
> Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
> http://www.adalog.fr

Thanks J-P. Rosen. Haven't taken advantage of declaring operators abstract before but now I will!

Best regards,
Joakim

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: gnat.string_split , howto manipulate slice numbers
  2019-10-29 23:06       ` J-P. Rosen
@ 2019-11-01  9:45         ` joakimds
  0 siblings, 0 replies; 21+ messages in thread
From: joakimds @ 2019-11-01  9:45 UTC (permalink / raw)


> Yes, but I do not recommend this "rename" method for wide use. Some
> decades ago, in an Ada 83 project which thus did not allow "use type",
> we had several bugs where copy-paste sloppiness resulted in (for
> example) some "-" operator renaming a "+" operator, with "amusing" results.

I haven't run into bugs associated with this myself but I did realize things could go wrong when using renamings and guessed the motivation for introducing "use type" in Ada95. Thanks for sharing you experiences Niklas.

> [Yet another shameless plug] AdaControl has a rule to check renamings
> with different names (precisely intended for eliminate this error)

Good to know J-P. Rosen, thanks.

Best regards,
Joakim


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2019-11-01  9:45 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29  1:54 gnat.string_split , howto manipulate slice numbers Alain De Vos
2019-10-29  8:17 ` briot.emmanuel
2019-10-29 16:56   ` Jeffrey R. Carter
2019-10-29 19:36     ` Niklas Holsti
2019-10-29 23:06       ` J-P. Rosen
2019-11-01  9:45         ` joakimds
2019-10-29 23:36   ` Stephen Leake
2019-10-29  8:35 ` Simon Wright
2019-10-29 11:08   ` Alain De Vos
2019-10-29 11:20     ` Alain De Vos
2019-10-29 16:44       ` J-P. Rosen
2019-10-29 16:47       ` Simon Wright
2019-10-29 18:33         ` J-P. Rosen
2019-10-29 19:37           ` Dmitry A. Kazakov
2019-10-30 11:30             ` Simon Wright
2019-10-31  9:30               ` joakimds
2019-10-31 10:12               ` Dmitry A. Kazakov
2019-10-31 18:36                 ` J-P. Rosen
2019-11-01  9:39                   ` joakimds
2019-10-29 16:41   ` Simon Wright
2019-10-29 16:53 ` Jeffrey R. Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox