comp.lang.ada
 help / color / mirror / Atom feed
* Return by reference
@ 1999-11-01  0:00 Brian Rogoff
  1999-11-02  0:00 ` Robert A Duff
  1999-11-02  0:00 ` Lutz Donnerhacke
  0 siblings, 2 replies; 22+ messages in thread
From: Brian Rogoff @ 1999-11-01  0:00 UTC (permalink / raw)


I understand why, for a return-by-reference type T, the function 

function Some_Func( ... ) return T is 
    Local_Var : T
begin
    ...
    return Local_Var;
end Some_Func;

causes Program_Error to be raised at run time, but I'm a bit 
perplexed as to why there is a problem for 

function Some_Func( Param : T; ... ) return T is
begin
    ...
    return Param;
end Some_Func;

Could someone explain why the latter case is problematic? 

-- Brian







^ permalink raw reply	[flat|nested] 22+ messages in thread
* Return by reference
@ 2017-12-17 14:38 Jere
  2017-12-17 14:57 ` Dmitry A. Kazakov
  2017-12-18 22:33 ` Randy Brukardt
  0 siblings, 2 replies; 22+ messages in thread
From: Jere @ 2017-12-17 14:38 UTC (permalink / raw)


Implicit dereference has gone a long way in providing
a sort of return by reference capability in Ada.  It is
still fairly clunky to setup and use though and requires
a lot of definitions that aren't always easy to read
and discern their purpose without lots of extra comments.
Additionally, it still exposes access types in places where
a designer may not want to at all.  Yes, it does so more
safely than before, but I know at least for me, I like to
avoid exposing access types as much as possible.

I was wondering if Ada could take a step with it further
and provide a syntax for return by reference.  The building
blocks for implementation (Implicit_Dereference based
holders) are already in the language now.  All that I was
curious about was a way to remove the hard to read, clunky
setup and a way to remove direct access to the underlying
access type.

I don't know if I have any good ideas for the syntax honestly.
The one idea that I came up with probably has holes:

function Stuff(Object : Some_Aliased_Type) return aliased Component_Type;

Basically this would expand out to (in the compiler implementation):

type Component_Type_Holder(Raw : not null access Component_Type)
   is limited null record;

function Stuff(Object : Some_Aliased_Type) return Component_Type_Holder;

as for what could be returned:
1.  Any aliased or tagged package level object
2.  Any function parameter object (or it's components) provided
    that the parameter is either explicitly aliased or tagged

Local variables to the function would not be allowed as sources

so

function Stuff(Object : Some_Aliased_Type) return aliased Component_Type is
begin
   return Object.Component;
end Stuff;

would be ok but:

function Stuff(Object : Some_Aliased_Type) return aliased Component_Type is
   Temp : Some_Aliased_Type;
begin
   return Temp.Component;
end Stuff;

would not be ok. 

Calling a return by reference within a function that returns
by reference would not be allowed directly, but require an unchecked_access
so that they can easily be identified and provide the programmer with
opportunity to really consider the source of his/her return value.

Again, I'm not necessarily proposing this is the right syntax, I just
wanted something to get people thinking.  Any syntax/implementation that
can improve this functionality is welcome.  I'm more interested in
hiding the access discriminant and cutting back on all the overly clunky
(though currently necessary) declarations that reduce readability.

Other thoughts are completely welcome.

I know it isn't as easy as I laid out, but I fell like the current
implicit_dereference method now gives compiler writers at least
a starting tool to take it a step further and enhance readability
and safety (less access types exposed).

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

end of thread, other threads:[~2017-12-19  1:29 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-01  0:00 Return by reference Brian Rogoff
1999-11-02  0:00 ` Robert A Duff
1999-11-02  0:00   ` Brian Rogoff
1999-11-03  0:00     ` Lutz Donnerhacke
1999-11-03  0:00       ` Brian Rogoff
1999-11-04  0:00         ` Lutz Donnerhacke
1999-11-06  0:00           ` Brian Rogoff
1999-11-07  0:00             ` Lutz Donnerhacke
1999-11-04  0:00       ` Robert A Duff
1999-11-03  0:00     ` Matthew Heaney
1999-11-03  0:00       ` Brian Rogoff
1999-11-03  0:00       ` Matthew Heaney
1999-11-02  0:00 ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2017-12-17 14:38 Jere
2017-12-17 14:57 ` Dmitry A. Kazakov
2017-12-18  0:51   ` Mehdi Saada
2017-12-18  8:18     ` Dmitry A. Kazakov
2017-12-18 10:47       ` Mehdi Saada
2017-12-18 12:16         ` Dmitry A. Kazakov
2017-12-18 22:41     ` Randy Brukardt
2017-12-18 22:33 ` Randy Brukardt
2017-12-19  1:29   ` Jere

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