comp.lang.ada
 help / color / mirror / Atom feed
* non record limited type
@ 2018-02-21 15:58 Mehdi Saada
  2018-02-21 21:42 ` Jere
  2018-02-22  1:29 ` Randy Brukardt
  0 siblings, 2 replies; 16+ messages in thread
From: Mehdi Saada @ 2018-02-21 15:58 UTC (permalink / raw)


I saw by trying it, that one could give a limited view, of a non-limited non-record type like
type FOO is limited private;
private
type FOO is new INTEGER;
, which I wasn't sure of just by reading the RM. That's a cool feature indeed, but why isn't it possible to write also
type FOO is limited range 1..5; ?
or    type FOO is limited array (INTEGER range <>) limited INTEGER;
I wasn't sure either from reading, but I can't compile anything similar. I don't understand why the possibility of forbidding copying isn't allowed for non record type.

Also, another question: if only the public view is limited, what about the parameter passing ? Is it by reference or copy, when such copy are made in the body ? I would guess by copy, but I prefer to ask


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

* Re: non record limited type
  2018-02-21 15:58 non record limited type Mehdi Saada
@ 2018-02-21 21:42 ` Jere
  2018-02-21 22:29   ` Mehdi Saada
  2018-02-22  1:29 ` Randy Brukardt
  1 sibling, 1 reply; 16+ messages in thread
From: Jere @ 2018-02-21 21:42 UTC (permalink / raw)


On Wednesday, February 21, 2018 at 10:58:18 AM UTC-5, Mehdi Saada wrote:
> 
> Also, another question: if only the public view is limited, what about the parameter passing ? Is it by reference or copy, when such copy are made in the body ? I would guess by copy, but I prefer to ask

I can't answer why on your first question, but on this one:
The RM in section 6.2 specifies how parameter passing is done based on the type.

http://www.ada-auth.org/standards/12rm/html/RM-6-2.html#I3382

Based on that, your limited private which is really an integer would still be
a by-copy-type.  I don't know the RM's intention but the wording suggests that
at least.  Note you can also used the "aliased" keyword in a function/procedure
signature to enforce an aliased variable which will be passed by reference
as well:

-- Object is passed by reference
procedure Do_Something(Object : aliased in out Some_Type);


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

* Re: non record limited type
  2018-02-21 21:42 ` Jere
@ 2018-02-21 22:29   ` Mehdi Saada
  2018-02-21 23:08     ` Jere
                       ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Mehdi Saada @ 2018-02-21 22:29 UTC (permalink / raw)


> Based on that, your limited private which is really an integer would still be
> a by-copy-type.  I don't know the RM's intention but the wording suggests that
> at least.  Note you can also used the "aliased" keyword in a function/procedure
> signature to enforce an aliased variable which will be passed by reference
> as well: 
> -- Object is passed by reference
> procedure Do_Something(Object : aliased in out Some_Type);

Really ? Are you sure it "forces" the passing by reference ? But I remember clearly have read somewhere, most probably on this forum that it wasn't in Ada's philosophy to let one precise that, since it is an implementation detail, and that the compiler shall decide by himself.
I can imagine that in some contexts, for small objects, or in distributed systems (across computers ), it would make sense for the value to be copied locally, then when "return" is reached it could be pasted back.
That said, in most cases your opinion makes more sense indeed. But I don't think one could be "sure".

That said Though I suppose you're right, 


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

* Re: non record limited type
  2018-02-21 22:29   ` Mehdi Saada
@ 2018-02-21 23:08     ` Jere
  2018-02-21 23:14     ` Jere
  2018-02-22  1:20     ` Randy Brukardt
  2 siblings, 0 replies; 16+ messages in thread
From: Jere @ 2018-02-21 23:08 UTC (permalink / raw)


On Wednesday, February 21, 2018 at 5:29:11 PM UTC-5, Mehdi Saada wrote:
> > Based on that, your limited private which is really an integer would still be
> > a by-copy-type.  I don't know the RM's intention but the wording suggests that
> > at least.  Note you can also used the "aliased" keyword in a function/procedure
> > signature to enforce an aliased variable which will be passed by reference
> > as well: 
> > -- Object is passed by reference
> > procedure Do_Something(Object : aliased in out Some_Type);
> 
> Really ? Are you sure it "forces" the passing by reference ? But I remember clearly have read somewhere, most probably on this forum that it wasn't in Ada's philosophy to let one precise that, since it is an implementation detail, and that the compiler shall decide by himself.

The rules are scattered about the RM, but if you look at the Ada2012 Rationale
document which was released with the RM:  
http://www.ada-auth.org/standards/rationale12.html

You will see it was a new feature added with the Ada2012 revision

Section 1.3.3
http://www.ada-auth.org/standards/12rat/html/Rat12-1-3-3.html
---------------------
An aliased parameter is always passed by reference and the accessibility 
rules are modified accordingly. This facility is used in a revision to 
the containers which avoids the need for expensive and unnecessary copying 
of complete elements when they are updated. The details will be given 
in Sections 4.2 and 6.3.



Section 4.2
http://www.ada-auth.org/standards/12rat/html/Rat12-4-2.html
---------------------
The other change in Ada 2012 concerning parameters is that they may be 
explicitly marked aliased thus

procedure P(X: aliased in out T; ... );

As a consequence within P we can write X'Access. Recall that tagged types 
were always considered implicitly aliased anyway and always passed by 
reference. If the type T is a by-copy type such as Integer, then adding 
aliased causes it to be passed by reference. (So by-copy types are not 
always passed by copy!)



Section 6.3
http://www.ada-auth.org/standards/12rat/html/Rat12-6-3.html
----------------------
The alert reader will note the inclusion of aliased for the parameter 
Container of the function Reference. As discussed in Section 4.2 on 
subprogram parameters, this ensures that the parameter is passed by 
reference (it always is for tagged types anyway); it also permits us 
to apply 'Access to the parameter Container within the function and to 
return that access value.

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

* Re: non record limited type
  2018-02-21 22:29   ` Mehdi Saada
  2018-02-21 23:08     ` Jere
@ 2018-02-21 23:14     ` Jere
  2018-02-22  0:09       ` Mehdi Saada
  2018-02-22  7:56       ` Simon Wright
  2018-02-22  1:20     ` Randy Brukardt
  2 siblings, 2 replies; 16+ messages in thread
From: Jere @ 2018-02-21 23:14 UTC (permalink / raw)


On Wednesday, February 21, 2018 at 5:29:11 PM UTC-5, Mehdi Saada wrote:
> > Based on that, your limited private which is really an integer would still be
> > a by-copy-type.  I don't know the RM's intention but the wording suggests that
> > at least.  Note you can also used the "aliased" keyword in a function/procedure
> > signature to enforce an aliased variable which will be passed by reference
> > as well: 
> > -- Object is passed by reference
> > procedure Do_Something(Object : aliased in out Some_Type);
> 
> Really ? Are you sure it "forces" the passing by reference ? But I remember clearly have read somewhere, most probably on this forum that it wasn't in Ada's philosophy to let one precise that, since it is an implementation detail, and that the compiler shall decide by himself.

Also, if you look into the section of the RM that I linked you in my first
response, you will see that it is required to be that way

RM 6.2
http://www.ada-auth.org/standards/12rm/html/RM-6-2.html
----------------------------------------------------------
A parameter of a by-reference type is passed by reference, as is an 
explicitly aliased parameter of any type. Each value of a by-reference 
type has an associated object. For a parenthesized expression, 
qualified_expression, or type_conversion, this object is the one 
associated with the operand. For a conditional_expression, this 
object is the one associated with the evaluated dependent_expression.

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

* Re: non record limited type
  2018-02-21 23:14     ` Jere
@ 2018-02-22  0:09       ` Mehdi Saada
  2018-02-22  0:26         ` Mehdi Saada
  2018-02-22 16:45         ` Jeffrey R. Carter
  2018-02-22  7:56       ` Simon Wright
  1 sibling, 2 replies; 16+ messages in thread
From: Mehdi Saada @ 2018-02-22  0:09 UTC (permalink / raw)


... Splendid. Did you have to search for me, or merely recalled (!) ?
Anyway, I just learnt a lot, thanks a lot
Infos scattered like that aren't the easiest ones to gather...
Yet, we still wonder why "type FOO is limited INTEGER" is not legal. Would be useful.


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

* Re: non record limited type
  2018-02-22  0:09       ` Mehdi Saada
@ 2018-02-22  0:26         ` Mehdi Saada
  2018-02-22  2:57           ` Jere
  2018-02-22 16:45         ` Jeffrey R. Carter
  1 sibling, 1 reply; 16+ messages in thread
From: Mehdi Saada @ 2018-02-22  0:26 UTC (permalink / raw)


... Splendid. Did you have to search for me, or merely recalled (!) ?
thanks a lot.


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

* Re: non record limited type
  2018-02-21 22:29   ` Mehdi Saada
  2018-02-21 23:08     ` Jere
  2018-02-21 23:14     ` Jere
@ 2018-02-22  1:20     ` Randy Brukardt
  2 siblings, 0 replies; 16+ messages in thread
From: Randy Brukardt @ 2018-02-22  1:20 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:6e384796-4a5f-449a-8bf7-3b8fe974b4fc@googlegroups.com...
...
>> -- Object is passed by reference
>> procedure Do_Something(Object : aliased in out Some_Type);
>
>Really ? Are you sure it "forces" the passing by reference ?

Yes, of course. It wouldn't make much sense to be able to save 'Access of a 
short-term local copy of the actual parameter -- you want the 'Access to 
directly access the actual object. (Recall the the original reason for 
"aliased" is to allow 'Access of the object. The rules for aliased 
parameters are a bit more complex, but the underlying issues are the same.)

Anyway, RM 6.2(10/4) specifically says: "A parameter of a by-reference type 
is passed by reference, as is an explicitly aliased parameter of any type."

                                  Randy.



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

* Re: non record limited type
  2018-02-21 15:58 non record limited type Mehdi Saada
  2018-02-21 21:42 ` Jere
@ 2018-02-22  1:29 ` Randy Brukardt
  2018-02-22  8:25   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 16+ messages in thread
From: Randy Brukardt @ 2018-02-22  1:29 UTC (permalink / raw)



"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:3a2e91d4-f563-4843-9c80-5a76732626d3@googlegroups.com...
>I saw by trying it, that one could give a limited view, of a non-limited 
>non-record type like
> type FOO is limited private;
> private
> type FOO is new INTEGER;
> , which I wasn't sure of just by reading the RM. That's a cool feature 
> indeed, but
> why isn't it possible to write also
> type FOO is limited range 1..5; ?
? Is it by reference or copy, when such copy are made in the body ? I would 
guess by copy, but I prefer to ask

The "limited private" rules stem from Ada 83, and thus exist for 
compatibility. (They work by implicitly making type limited.) The 
possibility of explicitly "limited" types is a much more recent innovation.

These types that become limited just because of "limited private" also have 
the nasty property of becoming non-limited when you can see the full 
declaration. This causes all kinds of semantic complications that we'd 
rather not repeat, so everything new requires declaring it limited 
explicitly and staying that way.

As to why there aren't limited elementary types (or limited array types, for 
that matter), no one has had any very compelling use for such a thing. 
Elementary types are by-copy, while explicitly limited types are 
by-reference types (see RM 6.2(7/3)). Generally, the "value" of a limited 
type includes the object identity in some sense, whereas values of 
elementary types are just values (the containing object being unimportant 
unless one is writing the value).

These sorts of things could be reconciled, but no one has offered any really 
compelling reasons to do so. And we don't generally do work just for the 
sake of doing it.

                                         Randy.


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

* Re: non record limited type
  2018-02-22  0:26         ` Mehdi Saada
@ 2018-02-22  2:57           ` Jere
  0 siblings, 0 replies; 16+ messages in thread
From: Jere @ 2018-02-22  2:57 UTC (permalink / raw)


On Wednesday, February 21, 2018 at 7:26:44 PM UTC-5, Mehdi Saada wrote:
> ... Splendid. Did you have to search for me, or merely recalled (!) ?
> thanks a lot.

A little of both.  I went to the RM index and did a search for 
"reference type" and it pointed right to 6.2.  I already knew it 
was in there some where (The Prego response [1]), I just had to 
search a bit to find out where.

[1] https://www.youtube.com/watch?v=2J87QekxQVI

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

* Re: non record limited type
  2018-02-21 23:14     ` Jere
  2018-02-22  0:09       ` Mehdi Saada
@ 2018-02-22  7:56       ` Simon Wright
  1 sibling, 0 replies; 16+ messages in thread
From: Simon Wright @ 2018-02-22  7:56 UTC (permalink / raw)


Jere <jhb.chat@gmail.com> writes:

> http://www.ada-auth.org/standards/12rm/html/RM-6-2.html

The latest revision is at

http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-TOC.html

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

* Re: non record limited type
  2018-02-22  1:29 ` Randy Brukardt
@ 2018-02-22  8:25   ` Dmitry A. Kazakov
  2018-02-22 23:24     ` Randy Brukardt
  0 siblings, 1 reply; 16+ messages in thread
From: Dmitry A. Kazakov @ 2018-02-22  8:25 UTC (permalink / raw)


On 22/02/2018 02:29, Randy Brukardt wrote:

> These types that become limited just because of "limited private" also have
> the nasty property of becoming non-limited when you can see the full
> declaration. This causes all kinds of semantic complications that we'd
> rather not repeat, so everything new requires declaring it limited
> explicitly and staying that way.

I don't see anything wrong with that, except for coupling to 
by-reference semantics. On/off visibility of the copying operation is 
all OK, it is just an operation. Parameter passing method is a different 
thing.

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


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

* Re: non record limited type
  2018-02-22  0:09       ` Mehdi Saada
  2018-02-22  0:26         ` Mehdi Saada
@ 2018-02-22 16:45         ` Jeffrey R. Carter
  2018-02-22 17:06           ` Dmitry A. Kazakov
  1 sibling, 1 reply; 16+ messages in thread
From: Jeffrey R. Carter @ 2018-02-22 16:45 UTC (permalink / raw)


On 02/22/2018 01:09 AM, Mehdi Saada wrote:
> Yet, we still wonder why "type FOO is limited INTEGER" is not legal. Would be useful.

For what?

-- 
Jeff Carter
"[A] brilliant military career that after thirty
years catapulted him to the rank of corporal."
Take the Money and Run
138

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

* Re: non record limited type
  2018-02-22 16:45         ` Jeffrey R. Carter
@ 2018-02-22 17:06           ` Dmitry A. Kazakov
  0 siblings, 0 replies; 16+ messages in thread
From: Dmitry A. Kazakov @ 2018-02-22 17:06 UTC (permalink / raw)


On 2018-02-22 17:45, Jeffrey R. Carter wrote:
> On 02/22/2018 01:09 AM, Mehdi Saada wrote:
>> Yet, we still wonder why "type FOO is limited INTEGER" is not legal. 
>> Would be useful.
> 
> For what?
    type Data is mod 2**16;
    type Hardware_Port is limited new Data;
    procedure Write (Port : Hardware_Port; Value : Data);

    Output : Hardware_Port;
    for Output 'Address use 16#0000_0010#;

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


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

* Re: non record limited type
  2018-02-22  8:25   ` Dmitry A. Kazakov
@ 2018-02-22 23:24     ` Randy Brukardt
  2018-02-23  8:58       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 16+ messages in thread
From: Randy Brukardt @ 2018-02-22 23:24 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:p6luqm$jb1$1@gioia.aioe.org...
> On 22/02/2018 02:29, Randy Brukardt wrote:
>
>> These types that become limited just because of "limited private" also 
>> have
>> the nasty property of becoming non-limited when you can see the full
>> declaration. This causes all kinds of semantic complications that we'd
>> rather not repeat, so everything new requires declaring it limited
>> explicitly and staying that way.
>
> I don't see anything wrong with that, except for coupling to by-reference 
> semantics. On/off visibility of the copying operation is all OK, it is 
> just an operation. Parameter passing method is a different thing.

Not to Ada: by-copy uses the assignment operation (which isn't quite the 
same thing as :=). Limited assignment is build-in-place only (for 
initialization purposes, another rule I know you hate). Probably could be 
different, but it would take extra work, and so far, there doesn't seem to 
be much need.

                                    Randy.


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

* Re: non record limited type
  2018-02-22 23:24     ` Randy Brukardt
@ 2018-02-23  8:58       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 16+ messages in thread
From: Dmitry A. Kazakov @ 2018-02-23  8:58 UTC (permalink / raw)


On 23/02/2018 00:24, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:p6luqm$jb1$1@gioia.aioe.org...
>> On 22/02/2018 02:29, Randy Brukardt wrote:
>>
>>> These types that become limited just because of "limited private" also
>>> have
>>> the nasty property of becoming non-limited when you can see the full
>>> declaration. This causes all kinds of semantic complications that we'd
>>> rather not repeat, so everything new requires declaring it limited
>>> explicitly and staying that way.
>>
>> I don't see anything wrong with that, except for coupling to by-reference
>> semantics. On/off visibility of the copying operation is all OK, it is
>> just an operation. Parameter passing method is a different thing.
> 
> Not to Ada: by-copy uses the assignment operation (which isn't quite the
> same thing as :=). Limited assignment is build-in-place only (for
> initialization purposes, another rule I know you hate). Probably could be
> different, but it would take extra work, and so far, there doesn't seem to
> be much need.

Right, but by-copy passing is not really assignment. It is a 
copy-constructor. When assignment finalizes the target, copy-constructor 
does not do anything. Ideally we should be able to disable ":=" while 
keeping by-copy passing. I can imagine use cases for short-lived smart 
pointers and iterators where I wanted no explicit copies made.

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

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

end of thread, other threads:[~2018-02-23  8:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-21 15:58 non record limited type Mehdi Saada
2018-02-21 21:42 ` Jere
2018-02-21 22:29   ` Mehdi Saada
2018-02-21 23:08     ` Jere
2018-02-21 23:14     ` Jere
2018-02-22  0:09       ` Mehdi Saada
2018-02-22  0:26         ` Mehdi Saada
2018-02-22  2:57           ` Jere
2018-02-22 16:45         ` Jeffrey R. Carter
2018-02-22 17:06           ` Dmitry A. Kazakov
2018-02-22  7:56       ` Simon Wright
2018-02-22  1:20     ` Randy Brukardt
2018-02-22  1:29 ` Randy Brukardt
2018-02-22  8:25   ` Dmitry A. Kazakov
2018-02-22 23:24     ` Randy Brukardt
2018-02-23  8:58       ` Dmitry A. Kazakov

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