comp.lang.ada
 help / color / mirror / Atom feed
* Standard missing a 'Negative' subtype?...
@ 2013-09-14  8:49 Martin
  2013-09-14  9:14 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Martin @ 2013-09-14  8:49 UTC (permalink / raw)


Why is there no "Negative" predefined subtype in package Standard?...

An implicit substype, something like:

   subtype Negative is Integer range Integer'First .. -1;

I would have thought this would fit nicely with 'Natural' and 'Positive'. Obviously not needed as often as those two, but when I finally did need it, it wasn't there!

-- Martin

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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
@ 2013-09-14  9:14 ` Dmitry A. Kazakov
  2013-09-14 19:13 ` mockturtle
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2013-09-14  9:14 UTC (permalink / raw)


On Sat, 14 Sep 2013 01:49:08 -0700 (PDT), Martin wrote:

> Why is there no "Negative" predefined subtype in package Standard?...

Because it is not needed. Positive is used in the definition of String.

> I would have thought this would fit nicely with 'Natural' and 'Positive'.
> Obviously not needed as often as those two, but when I finally did need
> it, it wasn't there!

You can always define it yourself.

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

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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
  2013-09-14  9:14 ` Dmitry A. Kazakov
@ 2013-09-14 19:13 ` mockturtle
  2013-10-01  2:45   ` J Kimball
  2013-09-14 19:57 ` Shark8
  2013-09-15  3:28 ` Jeffrey R. Carter
  3 siblings, 1 reply; 11+ messages in thread
From: mockturtle @ 2013-09-14 19:13 UTC (permalink / raw)



Sorry, I could not resist... :-)

   subtype Answer is Integer range 42 .. 42;


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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
  2013-09-14  9:14 ` Dmitry A. Kazakov
  2013-09-14 19:13 ` mockturtle
@ 2013-09-14 19:57 ` Shark8
  2013-09-15  3:28 ` Jeffrey R. Carter
  3 siblings, 0 replies; 11+ messages in thread
From: Shark8 @ 2013-09-14 19:57 UTC (permalink / raw)


On Saturday, September 14, 2013 2:49:08 AM UTC-6, Martin wrote:
> Why is there no "Negative" predefined subtype in package Standard?...

Because you don't often need strictly negative numbers... but if you do you could use the following Ada 2012 construct:

    subtype Negative is Integer
    with Static_Predicate => Negative not in Natural;

Or the more traditional Ada83 Range:

    subtype Negative is Integer is range
         Integer'First..Integer'Pred(Natural'First); -- or Integer'First..-1.

(I like using use Integer/Natural/Positive attributes when defining things in terms of subtypes because it avoids hardcoded-constants and makes the type/sybtype relations obvious: the definition becomes stated in terms of it's "type-class".)


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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
                   ` (2 preceding siblings ...)
  2013-09-14 19:57 ` Shark8
@ 2013-09-15  3:28 ` Jeffrey R. Carter
  2013-09-15  7:36   ` Simon Wright
  3 siblings, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2013-09-15  3:28 UTC (permalink / raw)


On 09/14/2013 01:49 AM, Martin wrote:
> Why is there no "Negative" predefined subtype in package Standard?...
>
> An implicit substype, something like:
>
> subtype Negative is Integer range Integer'First .. -1;
>
> I would have thought this would fit nicely with 'Natural' and 'Positive'. Obviously not needed as often as those two,
> but when I finally did need it, it wasn't there!

Nor are there Non_Negative (Integer'First .. 0), Reasonable_String_Index (1 .. 256 [or something]), or many others one 
could think of. Natural and Positive are used in the definition of other things in the ARM; nothing needed Negative (or 
any other subtypes).

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-15  3:28 ` Jeffrey R. Carter
@ 2013-09-15  7:36   ` Simon Wright
  2013-09-15 16:07     ` Jeffrey R. Carter
  2013-09-15 16:49     ` Martin
  0 siblings, 2 replies; 11+ messages in thread
From: Simon Wright @ 2013-09-15  7:36 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:

>             Natural and Positive are used in the definition of
> other things in the ARM; nothing needed Negative (or any other
> subtypes).

"because they are needed in other parts of the ARM" shouldn't be the
only criterion! "what users [i.e., we developers] would find useful"
should be considered too - otherwise we wouldn't have Ada.Containers,
for example.

That said, Negative seems to come well below the bar.

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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-15  7:36   ` Simon Wright
@ 2013-09-15 16:07     ` Jeffrey R. Carter
  2013-09-15 16:49     ` Martin
  1 sibling, 0 replies; 11+ messages in thread
From: Jeffrey R. Carter @ 2013-09-15 16:07 UTC (permalink / raw)


On 09/15/2013 12:36 AM, Simon Wright wrote:
>
> "because they are needed in other parts of the ARM" shouldn't be the
> only criterion! "what users [i.e., we developers] would find useful"
> should be considered too - otherwise we wouldn't have Ada.Containers,
> for example.

True. However, these things have been around since the beginning. I don't have access to ARM-80, but even ARM-83 doesn't 
have a lot of things that would be useful, such as a math library.

> That said, Negative seems to come well below the bar.

Apparently the bar was a lot higher when the predefined subtypes of Integer were created.

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---


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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-15  7:36   ` Simon Wright
  2013-09-15 16:07     ` Jeffrey R. Carter
@ 2013-09-15 16:49     ` Martin
  2013-09-15 17:51       ` J-P. Rosen
  2013-09-16 17:44       ` Adam Beneschan
  1 sibling, 2 replies; 11+ messages in thread
From: Martin @ 2013-09-15 16:49 UTC (permalink / raw)


On Sunday, September 15, 2013 8:36:56 AM UTC+1, Simon Wright wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:
> 
> 
> 
> >             Natural and Positive are used in the definition of
> 
> > other things in the ARM; nothing needed Negative (or any other
> 
> > subtypes).
> 
> 
> 
> "because they are needed in other parts of the ARM" shouldn't be the
> 
> only criterion! "what users [i.e., we developers] would find useful"
> 
> should be considered too - otherwise we wouldn't have Ada.Containers,
> 
> for example.
> 
> 
> 
> That said, Negative seems to come well below the bar.

Sure, and adding it now might cause all sorts of issues...

...just a shame it wasn't considered from the start...if only for symmetry!

I'm still waiting on Ada.Networks...


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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-15 16:49     ` Martin
@ 2013-09-15 17:51       ` J-P. Rosen
  2013-09-16 17:44       ` Adam Beneschan
  1 sibling, 0 replies; 11+ messages in thread
From: J-P. Rosen @ 2013-09-15 17:51 UTC (permalink / raw)


Le 15/09/2013 18:49, Martin a écrit :
>> That said, Negative seems to come well below the bar.
> Sure, and adding it now might cause all sorts of issues...
> 
> ...just a shame it wasn't considered from the start...if only for symmetry!
Well, it's better to have the strict minimum in Standard.

For one thing, everything in Standard is visible everywhere, and clashes
with everything the user would define (it is "more" visible than
use-visible elements).

String was necessary in the language, therefore Positive was necessary.
The rest should go in other (regular) packages. You can regret that
Ada83 had not more predefined packages, but in any case, those things
would not have been put in Standard.

-- 
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] 11+ messages in thread

* Re: Standard missing a 'Negative' subtype?...
  2013-09-15 16:49     ` Martin
  2013-09-15 17:51       ` J-P. Rosen
@ 2013-09-16 17:44       ` Adam Beneschan
  1 sibling, 0 replies; 11+ messages in thread
From: Adam Beneschan @ 2013-09-16 17:44 UTC (permalink / raw)


On Sunday, September 15, 2013 9:49:10 AM UTC-7, Martin wrote:

> ...just a shame it wasn't considered from the start...if only for symmetry!

Ada was intended as a tool, not as a work of art.  So I guess this is a little like saying my Black & Decker drill has a mode switch on the right side, so they should have put one on the left side too, for symmetry.  :) :)

                             -- Adam

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

* Re: Standard missing a 'Negative' subtype?...
  2013-09-14 19:13 ` mockturtle
@ 2013-10-01  2:45   ` J Kimball
  0 siblings, 0 replies; 11+ messages in thread
From: J Kimball @ 2013-10-01  2:45 UTC (permalink / raw)


On 09/14/2013 02:13 PM, mockturtle wrote:
> 
> Sorry, I could not resist... :-)
> 
>    subtype Answer is Integer range 42 .. 42;
> 
> 

I'd prefer a static predicate:

   subtype Answer is Integer with Static_Predicate => Answer = 42;


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

end of thread, other threads:[~2013-10-01  2:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
2013-09-14  9:14 ` Dmitry A. Kazakov
2013-09-14 19:13 ` mockturtle
2013-10-01  2:45   ` J Kimball
2013-09-14 19:57 ` Shark8
2013-09-15  3:28 ` Jeffrey R. Carter
2013-09-15  7:36   ` Simon Wright
2013-09-15 16:07     ` Jeffrey R. Carter
2013-09-15 16:49     ` Martin
2013-09-15 17:51       ` J-P. Rosen
2013-09-16 17:44       ` Adam Beneschan

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