* We should introduce aliased types
@ 2014-08-01 18:54 Victor Porton
2014-08-01 18:56 ` Victor Porton
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Victor Porton @ 2014-08-01 18:54 UTC (permalink / raw)
I think we should introduce aliased types to allow self-referencing objects
and objects which we can access for object's internal purposes:
type T is aliased
record
Ptr: access all T;
end;
Every value of an aliased type should be aliased (whether we specify that
the particular value if aliased or don't specify).
Then we could create a self-referencing object by a code (say in Initialize)
like this:
declare
X: T;
begin
X.Ptr = X.Unchecked_Access;
end;
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 18:54 We should introduce aliased types Victor Porton
@ 2014-08-01 18:56 ` Victor Porton
2014-08-01 19:16 ` Victor Porton
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Victor Porton @ 2014-08-01 18:56 UTC (permalink / raw)
Victor Porton wrote:
> I think we should introduce aliased types to allow self-referencing
> objects and objects which we can access for object's internal purposes:
>
> type T is aliased
> record
> Ptr: access all T;
> end;
>
> Every value of an aliased type should be aliased (whether we specify that
> the particular value if aliased or don't specify).
>
> Then we could create a self-referencing object by a code (say in
> Initialize) like this:
>
> declare
> X: T;
> begin
> X.Ptr = X.Unchecked_Access;
> end;
It sometimes make sense to make only the private view of a type aliased.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 18:54 We should introduce aliased types Victor Porton
2014-08-01 18:56 ` Victor Porton
@ 2014-08-01 19:16 ` Victor Porton
2014-08-01 19:47 ` Randy Brukardt
2014-08-01 19:44 ` Randy Brukardt
2014-08-01 20:39 ` sbelmont700
3 siblings, 1 reply; 8+ messages in thread
From: Victor Porton @ 2014-08-01 19:16 UTC (permalink / raw)
Victor Porton wrote:
> I think we should introduce aliased types to allow self-referencing
> objects and objects which we can access for object's internal purposes:
>
> type T is aliased
> record
> Ptr: access all T;
> end;
>
> Every value of an aliased type should be aliased (whether we specify that
> the particular value if aliased or don't specify).
>
> Then we could create a self-referencing object by a code (say in
> Initialize) like this:
>
> declare
> X: T;
> begin
> X.Ptr = X.Unchecked_Access;
> end;
One situation in which we need aliased types (not a single aliased variable)
is Initialize() procedure for controlled types.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 18:54 We should introduce aliased types Victor Porton
2014-08-01 18:56 ` Victor Porton
2014-08-01 19:16 ` Victor Porton
@ 2014-08-01 19:44 ` Randy Brukardt
2014-08-01 19:49 ` Randy Brukardt
2014-08-01 20:39 ` sbelmont700
3 siblings, 1 reply; 8+ messages in thread
From: Randy Brukardt @ 2014-08-01 19:44 UTC (permalink / raw)
"Victor Porton" <porton@narod.ru> wrote in message
news:lrgnoc$di6$1@speranza.aioe.org...
>I think we should introduce aliased types to allow self-referencing objects
> and objects which we can access for object's internal purposes:
>
> type T is aliased
> record
> Ptr: access all T;
> end;
>
> Every value of an aliased type should be aliased (whether we specify that
> the particular value if aliased or don't specify).
You do know that this is already true of almost all limited types (without
any declaration)?
I.e.
type T;
type Ptr_Holder (D : access T) is limited null record;
type T is limited record
Ptr : Ptr_Holder (T'Access);
end record;
is legal Ada.
It's not allowed for non-limited types because assigning the object would
break the self-referential link (it would point to the wrong object
afterwards).
And you can't directly declare a component as
Ptr : access T := T'Access;
because of accessibility; the problem isn't whether T is aliased or not.
"access T" is a library-level type, while T'Access might refer to a local
object, so the access type could outlive the object (in particular, this
component could be copied into an object of another library-level type), and
that's not allowed.
Your idea would have to have the same restriction, so it wouldn't help any.
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 19:16 ` Victor Porton
@ 2014-08-01 19:47 ` Randy Brukardt
2014-08-01 19:57 ` Victor Porton
0 siblings, 1 reply; 8+ messages in thread
From: Randy Brukardt @ 2014-08-01 19:47 UTC (permalink / raw)
"Victor Porton" <porton@narod.ru> wrote in message
news:lrgp2h$h3n$1@speranza.aioe.org...
...
> One situation in which we need aliased types (not a single aliased
> variable)
> is Initialize() procedure for controlled types.
This is already true. Controlled types are by-reference, so it's legal to
take 'Access of a subprogram parameter of the type. Specifically:
procedure Initialize (Obj : T) is
begin
Obj.Ptr := T'Unchecked_Access;
end Initialize;
is legal.
Did you actually try this before writing??
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 19:44 ` Randy Brukardt
@ 2014-08-01 19:49 ` Randy Brukardt
0 siblings, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2014-08-01 19:49 UTC (permalink / raw)
"Randy Brukardt" <randy@rrsoftware.com> wrote in message
news:lrgqnq$4i3$1@loke.gir.dk...
> "Victor Porton" <porton@narod.ru> wrote in message
...
> And you can't directly declare a component as
> Ptr : access T := T'Access;
> because of accessibility; the problem isn't whether T is aliased or not.
> "access T" is a library-level type, while T'Access might refer to a local
> object, so the access type could outlive the object (in particular, this
> component could be copied into an object of another library-level type),
> and that's not allowed.
Actually, you can do that so long as you use Unchecked_Access:
type T is limited record
Ptr : access T := T'Unchecked_Access;
end record;
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 19:47 ` Randy Brukardt
@ 2014-08-01 19:57 ` Victor Porton
0 siblings, 0 replies; 8+ messages in thread
From: Victor Porton @ 2014-08-01 19:57 UTC (permalink / raw)
Randy Brukardt wrote:
> "Victor Porton" <porton@narod.ru> wrote in message
> news:lrgp2h$h3n$1@speranza.aioe.org...
> ...
>> One situation in which we need aliased types (not a single aliased
>> variable)
>> is Initialize() procedure for controlled types.
>
> This is already true. Controlled types are by-reference, so it's legal to
> take 'Access of a subprogram parameter of the type. Specifically:
>
> procedure Initialize (Obj : T) is
> begin
> Obj.Ptr := T'Unchecked_Access;
> end Initialize;
>
> is legal.
>
> Did you actually try this before writing??
Sorry, Randy. I've tried but not with a tagged type. Now I see it does
already work with tagged types.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: We should introduce aliased types
2014-08-01 18:54 We should introduce aliased types Victor Porton
` (2 preceding siblings ...)
2014-08-01 19:44 ` Randy Brukardt
@ 2014-08-01 20:39 ` sbelmont700
3 siblings, 0 replies; 8+ messages in thread
From: sbelmont700 @ 2014-08-01 20:39 UTC (permalink / raw)
On Friday, August 1, 2014 2:54:06 PM UTC-4, Victor Porton wrote:
> I think we should introduce aliased types to allow self-referencing objects
>
> and objects which we can access for object's internal purposes:
>
I would rather see "not aliased" subprogram parameters (and I guess also return values) to help do fun things with constructor functions. At the very least it would make smart pointers safer, but I have lots of other dreams about limited types (though it would probably be too complex to really work).
-sb
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-08-01 20:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 18:54 We should introduce aliased types Victor Porton
2014-08-01 18:56 ` Victor Porton
2014-08-01 19:16 ` Victor Porton
2014-08-01 19:47 ` Randy Brukardt
2014-08-01 19:57 ` Victor Porton
2014-08-01 19:44 ` Randy Brukardt
2014-08-01 19:49 ` Randy Brukardt
2014-08-01 20:39 ` sbelmont700
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox