comp.lang.ada
 help / color / mirror / Atom feed
* Ada202X : alternate syntax for ranged scalars
@ 2013-04-26 10:10 Martin
  2013-04-26 10:35 ` Peter C. Chapin
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Martin @ 2013-04-26 10:10 UTC (permalink / raw)


The default scalar declarations are 'closed ranges', i.e. include both upper and lower in the valid range.

Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.

I'm floating (pun intended) an alternative syntax for specify such ranges (or 'intervals')...

type Degree is digits 15 range [0.0, 360.0); -- includes 0 but not 360


The current 'closed ranges' would be:

type Degree is digits 15 range [0.0, 360.0]; -- includes 0 and 360


Fully open range, i.e. not include 0.0 or 360.0:

type Degree is digits 15 range (0.0, 360.0); -- includes neither 0 nor 360


A 'reverse' half open range, i.e. not include 0.0 but including 360.0:

type Degree is digits 15 range (0.0, 360.0]; -- excludes 0 but includes 360



Usual rules would apply to the simple expression between the brackets.


Any thoughts?
-- Martin



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
@ 2013-04-26 10:35 ` Peter C. Chapin
  2013-04-26 12:26 ` Eryndlia Mavourneen
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Peter C. Chapin @ 2013-04-26 10:35 UTC (permalink / raw)



On 04/26/2013 06:10 AM, Martin wrote:

> The default scalar declarations are 'closed ranges', i.e. include both upper and lower in the valid range.
>
> Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.
>
> I'm floating (pun intended) an alternative syntax for specify such ranges (or 'intervals')...
>
> type Degree is digits 15 range [0.0, 360.0); -- includes 0 but not 360

I'm not sure how important this is, but your proposed syntax will cause 
fits for editors that do generic brace matching and/or auto-indentation. 
I understand that an Ada-aware editor could be expected to do the right 
thing, but it's nice when simple algorithms allow things to 'just work.'

That said, Ada already causes simple syntax highlighting editors 
problems with the use of ' for both character constants and as an 
attribute delimiter. That doesn't seem like a good reason to make 
matters worse, however.

Peter



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
  2013-04-26 10:35 ` Peter C. Chapin
@ 2013-04-26 12:26 ` Eryndlia Mavourneen
  2013-05-02  2:11   ` Randy Brukardt
  2013-04-26 12:53 ` AdaMagica
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Eryndlia Mavourneen @ 2013-04-26 12:26 UTC (permalink / raw)


On Friday, April 26, 2013 5:10:01 AM UTC-5, Martin wrote:
> The default scalar declarations are 'closed ranges', i.e. include both upper and lower in the valid range.
> 
> Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.
> 
> I'm floating (pun intended) an alternative syntax for specify such ranges (or 'intervals')...
> 
> type Degree is digits 15 range [0.0, 360.0); -- includes 0 but not 360
> 
> The current 'closed ranges' would be:
> type Degree is digits 15 range [0.0, 360.0]; -- includes 0 and 360
> 
> Fully open range, i.e. not include 0.0 or 360.0:
> 
> type Degree is digits 15 range (0.0, 360.0); -- includes neither 0 nor 360
> 
> A 'reverse' half open range, i.e. not include 0.0 but including 360.0:
> 
> Usual rules would apply to the simple expression between the brackets.
> 
> Any thoughts?
> -- Martin

I agree with Peter.  A syntax more closely allied with current syntax might be:

  type Degree is digits 15 range 0.0 .. not 360.0; -- includes 0 but not 360
 
The current 'closed ranges' would be the same as now:
  type Degree is digits 15 range 0.0 .. 360.0; -- includes 0 and 360
 
Fully open range, i.e. not include 0.0 or 360.0:
 
 type Degree is digits 15 range not 0.0 .. not 360.0; -- includes neither 0 nor 360

That said, we must assume that floating point values get translated *exactly*; that is, 360.0 does not get translated to a machine type of 359.999999... or 360.0111111...

-- Eryndlia F. Mavourneen



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
  2013-04-26 10:35 ` Peter C. Chapin
  2013-04-26 12:26 ` Eryndlia Mavourneen
@ 2013-04-26 12:53 ` AdaMagica
  2013-04-26 14:46   ` Shark8
  2013-04-28  2:11   ` Stephen Leake
  2013-04-26 16:55 ` Jeffrey Carter
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 11+ messages in thread
From: AdaMagica @ 2013-04-26 12:53 UTC (permalink / raw)


On Friday, April 26, 2013 12:10:01 PM UTC+2, Martin wrote:

> Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.

What about the attributes Succ and Pred RM 3.5 (22-27)?

type Angle is digits D;
subtype Normalized_Angle is Angle range -180.0 .. Angle'Pred (+180.0);



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 12:53 ` AdaMagica
@ 2013-04-26 14:46   ` Shark8
  2013-04-28  2:11   ` Stephen Leake
  1 sibling, 0 replies; 11+ messages in thread
From: Shark8 @ 2013-04-26 14:46 UTC (permalink / raw)


On Friday, April 26, 2013 6:53:26 AM UTC-6, AdaMagica wrote:
> On Friday, April 26, 2013 12:10:01 PM UTC+2, Martin wrote:
> >
> > Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0. 
> 
> What about the attributes Succ and Pred RM 3.5 (22-27)?
>  
> type Angle is digits D;
> subtype Normalized_Angle is Angle range -180.0 .. Angle'Pred (+180.0);

Yes, that should work much better.



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
                   ` (2 preceding siblings ...)
  2013-04-26 12:53 ` AdaMagica
@ 2013-04-26 16:55 ` Jeffrey Carter
  2013-05-02 23:05 ` Jerry
  2013-05-14 22:30 ` Martin
  5 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2013-04-26 16:55 UTC (permalink / raw)


On 04/26/2013 03:10 AM, Martin wrote:
> The default scalar declarations are 'closed ranges', i.e. include both upper and lower in the valid range.
>
> Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.
>
> I'm floating (pun intended) an alternative syntax for specify such ranges (or 'intervals')...
>
> type Degree is digits 15 range [0.0, 360.0); -- includes 0 but not 360

I dislike the proposal. It's far too easy to miss the subtle distinction between 
a bracket and a parenthesis.

-- 
Jeff Carter
"My legs are gray, my ears are gnarled, my eyes are old and bent."
Monty Python's Life of Brian
81



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 12:53 ` AdaMagica
  2013-04-26 14:46   ` Shark8
@ 2013-04-28  2:11   ` Stephen Leake
  1 sibling, 0 replies; 11+ messages in thread
From: Stephen Leake @ 2013-04-28  2:11 UTC (permalink / raw)


AdaMagica <christ-usch.grein@t-online.de> writes:

> On Friday, April 26, 2013 12:10:01 PM UTC+2, Martin wrote:
>
>> Sometimes we would like to specify a 'half open range', e.g. values
>> of degree from 0.0 up to BUT NOT INCLUDING 360.0.
>
> What about the attributes Succ and Pred RM 3.5 (22-27)?
>
> type Angle is digits D;
> subtype Normalized_Angle is Angle range -180.0 .. Angle'Pred (+180.0);

+1

-- 
-- Stephe



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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 12:26 ` Eryndlia Mavourneen
@ 2013-05-02  2:11   ` Randy Brukardt
  2013-05-02 13:29     ` Eryndlia Mavourneen
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2013-05-02  2:11 UTC (permalink / raw)


"Eryndlia Mavourneen" <eryndlia@gmail.com> wrote in message 
news:3861a3cd-2513-4871-9062-2f2a53eb106b@googlegroups.com...
>...
> That said, we must assume that floating point values get translated 
> *exactly*; that is,
>360.0 does not get translated to a machine type of 359.999999... or 
>360.0111111...

Which of course makes no sense for most literals; it can only make sense for 
values that already correspond to machine numbers, and those already require 
exact conversion.

The problem I see with such syntax is what precisely happens when the bound 
is not specified as a machine number? Say:
                     type My_Flt digits 5 range not 0.6 .. not 2.6;

Is this the same as the range without the "nots"? Or is it requiring 
something less than some unknown value in a particular interval? I don't see 
how that would be useful. Or are you going to require selecting a 
*particular* machine number in this case? That would be a massive change 
from the behavior of Ada currently, and probably would break some programs 
(that aren't portable but do work) be changing the values of their literals.

The bounds of the range have to be machine numbers, as they don't have to be 
static; as such, we don't care about values that aren't machine numbers. So 
what exactly is this gaining over:

        subtype My_Flt is Float range Float'Succ(0.0)..Float'Pred(360.0);

                                         Randy.




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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-05-02  2:11   ` Randy Brukardt
@ 2013-05-02 13:29     ` Eryndlia Mavourneen
  0 siblings, 0 replies; 11+ messages in thread
From: Eryndlia Mavourneen @ 2013-05-02 13:29 UTC (permalink / raw)


On Wednesday, May 1, 2013 9:11:50 PM UTC-5, Randy Brukardt wrote:
> "Eryndlia Mavourneen" <eryndlia@gmail.com> wrote in message 
> news:3861a3cd-2513-4871-9062-2f2a53eb106b@googlegroups.com...
> 
> >...
> > That said, we must assume that floating point values get translated 
> > *exactly*; that is,
> >360.0 does not get translated to a machine type of 359.999999... or 
> >360.0111111...
>
> So what exactly is this gaining over:
>         subtype My_Flt is Float range Float'Succ(0.0)..Float'Pred(360.0);
> 
>                                          Randy.

Nothing that I see.  I prefer the already available syntax of 'Pred and 'Succ.  My note was merely offering up an alternative syntax to the Op's, if something special were required for any reason.

-- Eryndlia

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

* Re: Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
                   ` (3 preceding siblings ...)
  2013-04-26 16:55 ` Jeffrey Carter
@ 2013-05-02 23:05 ` Jerry
  2013-05-14 22:30 ` Martin
  5 siblings, 0 replies; 11+ messages in thread
From: Jerry @ 2013-05-02 23:05 UTC (permalink / raw)


On Friday, April 26, 2013 3:10:01 AM UTC-7, Martin wrote:
> The default scalar declarations are 'closed ranges', i.e. include both upper and lower in the valid range.
> Sometimes we would like to specify a 'half open range', e.g. values of degree from 0.0 up to BUT NOT INCLUDING 360.0.
> I'm floating (pun intended) an alternative syntax for specify such ranges (or 'intervals')...
> type Degree is digits 15 range [0.0, 360.0); -- includes 0 but not 360
> 
> The current 'closed ranges' would be:
> type Degree is digits 15 range [0.0, 360.0]; -- includes 0 and 360
> 
> Fully open range, i.e. not include 0.0 or 360.0:
> type Degree is digits 15 range (0.0, 360.0); -- includes neither 0 nor 360
> 
> A 'reverse' half open range, i.e. not include 0.0 but including 360.0:
> type Degree is digits 15 range (0.0, 360.0]; -- excludes 0 but includes 360
> 
> Usual rules would apply to the simple expression between the brackets.
> 
> Any thoughts?
> -- Martin

If Ada introduces [ and ] please let them be for array indices.
Jerry


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

* Ada202X : alternate syntax for ranged scalars
  2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
                   ` (4 preceding siblings ...)
  2013-05-02 23:05 ` Jerry
@ 2013-05-14 22:30 ` Martin
  5 siblings, 0 replies; 11+ messages in thread
From: Martin @ 2013-05-14 22:30 UTC (permalink / raw)


Some good points against...

For reference, the inspiration for the syntax was ISO 31-11 (https://en.wikipedia.org/wiki/ISO_31-11)... Which I'm using to try and map between a modelling tool and a semantic analysis tool.

-- Martin


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

end of thread, other threads:[~2013-05-14 22:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-26 10:10 Ada202X : alternate syntax for ranged scalars Martin
2013-04-26 10:35 ` Peter C. Chapin
2013-04-26 12:26 ` Eryndlia Mavourneen
2013-05-02  2:11   ` Randy Brukardt
2013-05-02 13:29     ` Eryndlia Mavourneen
2013-04-26 12:53 ` AdaMagica
2013-04-26 14:46   ` Shark8
2013-04-28  2:11   ` Stephen Leake
2013-04-26 16:55 ` Jeffrey Carter
2013-05-02 23:05 ` Jerry
2013-05-14 22:30 ` Martin

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