comp.lang.ada
 help / color / mirror / Atom feed
* why only in-parameters in functions
@ 2004-09-29 15:18 Rick Santa-Cruz
  2004-09-29 15:30 ` stephane richard
  2004-09-29 16:55 ` Alexander E. Kopilovich
  0 siblings, 2 replies; 10+ messages in thread
From: Rick Santa-Cruz @ 2004-09-29 15:18 UTC (permalink / raw)


Hi,

I know that it is only allowed to use in-parameters with functions. But I 
can't figure out what is the idea behind this. Why did the Ada-Team only 
allow in-parameter when using functions?

Thanks in advance,
Rick 





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

* Re: why only in-parameters in functions
  2004-09-29 15:18 why only in-parameters in functions Rick Santa-Cruz
@ 2004-09-29 15:30 ` stephane richard
  2004-09-29 16:55 ` Alexander E. Kopilovich
  1 sibling, 0 replies; 10+ messages in thread
From: stephane richard @ 2004-09-29 15:30 UTC (permalink / raw)



"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> wrote in message 
news:cjejo4$62e$00$1@news.t-online.com...
> Hi,
>
> I know that it is only allowed to use in-parameters with functions. But I 
> can't figure out what is the idea behind this. Why did the Ada-Team only 
> allow in-parameter when using functions?
>
> Thanks in advance,
> Rick
>
Maybe I can answer that, with my still very limited knowledge...and wait for 
others to correct me ;-).

I would assume that since a function returns a value Out parameters would 
also allow to change values outside the function.  even if it's available in 
other languages, it's usually recommended to not do so for good practice. 
so to enforce it isn't all that bad a thing. :-).






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

* Re: why only in-parameters in functions
  2004-09-29 15:18 why only in-parameters in functions Rick Santa-Cruz
  2004-09-29 15:30 ` stephane richard
@ 2004-09-29 16:55 ` Alexander E. Kopilovich
  2004-09-29 21:10   ` Randy Brukardt
                     ` (3 more replies)
  1 sibling, 4 replies; 10+ messages in thread
From: Alexander E. Kopilovich @ 2004-09-29 16:55 UTC (permalink / raw)
  To: comp.lang.ada

Rick Santa-Cruz wrote:

> I know that it is only allowed to use in-parameters with functions. But I 
> can't figure out what is the idea behind this. Why did the Ada-Team only 
> allow in-parameter when using functions?

There were so many discussions on this matter, at various levels, and so manu
arguments pro and contra were expressed that perhaps there should be FAQ for
this topic alone.

In short, for many years Ada community and ARG (which can be seen as Ada
design team) were (and still are) divided about this matter.

In practice, where you really need in-parameters for a function you may either
use a procedure that returns value (if you use GNAT compiler) or you may use
the construct, presented here in c.l.a by Robert I. Eachus (see his message
in comp.lang.ada from 2003-07-15 with Subject: Re: What evil would happen?)

----------------------------------------------------------------------------

function Random(Gen: in Generator) return ...
   Local: Generator;
   for Local'Address use Gen'Address;
begin
   ...
end Random;

----------------------------------------------------------------------------




Alexander Kopilovich                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia





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

* Re: why only in-parameters in functions
  2004-09-29 16:55 ` Alexander E. Kopilovich
@ 2004-09-29 21:10   ` Randy Brukardt
  2004-09-29 23:37     ` Björn Persson
  2004-09-29 21:12   ` Florian Weimer
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Randy Brukardt @ 2004-09-29 21:10 UTC (permalink / raw)


"Alexander E. Kopilovich" <aek@VB1162.spb.edu> wrote in message
news:mailman.131.1096477841.390.comp.lang.ada@ada-france.org...
> Rick Santa-Cruz wrote:
>
> > I know that it is only allowed to use in-parameters with functions. But
I
> > can't figure out what is the idea behind this. Why did the Ada-Team only
> > allow in-parameter when using functions?
>
> There were so many discussions on this matter, at various levels, and so
manu
> arguments pro and contra were expressed that perhaps there should be FAQ
for
> this topic alone.
>
> In short, for many years Ada community and ARG (which can be seen as Ada
> design team) were (and still are) divided about this matter.

The most recent go-round is saved in AI-323. And, yes, opinion is divided
enough that it is unlikely to ever change.

> In practice, where you really need in-parameters for a function you may
either
> use a procedure that returns value (if you use GNAT compiler) or you may
use
> the construct, presented here in c.l.a by Robert I. Eachus (see his
message
> in comp.lang.ada from 2003-07-15 with Subject: Re: What evil would
happen?)

The easiest thing to do is to use an access parameter instead. That's
somewhat ugly (because it messes up the calls as 'Access is needed), but it
works.

If you are willing to depend on the definition of the type, a number of
things (including the solution suggested previously) work. Another solution
(used by Ada.Text_IO, for example) is to insure that the type passed is just
a handle to the real object. Controlled types make this solution relatively
easy to write.

                                  Randy.







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

* Re: why only in-parameters in functions
  2004-09-29 16:55 ` Alexander E. Kopilovich
  2004-09-29 21:10   ` Randy Brukardt
@ 2004-09-29 21:12   ` Florian Weimer
  2004-09-30  7:41     ` Dmitry A. Kazakov
  2004-09-29 22:42   ` Wojtek Narczynski
  2004-09-30  1:55   ` Matthew Heaney
  3 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2004-09-29 21:12 UTC (permalink / raw)


* Alexander E. Kopilovich:

> In practice, where you really need in-parameters for a function you may either
> use a procedure that returns value (if you use GNAT compiler) or you may use
> the construct, presented here in c.l.a by Robert I. Eachus (see his message
> in comp.lang.ada from 2003-07-15 with Subject: Re: What evil would happen?)

The "Rosen trick" is also relevant in this context (see the archives),
but it only works for limited types.  However, it should be used
whenever possible because it does not involve erroneous execution.



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

* Re: why only in-parameters in functions
  2004-09-29 16:55 ` Alexander E. Kopilovich
  2004-09-29 21:10   ` Randy Brukardt
  2004-09-29 21:12   ` Florian Weimer
@ 2004-09-29 22:42   ` Wojtek Narczynski
  2004-09-30  1:55   ` Matthew Heaney
  3 siblings, 0 replies; 10+ messages in thread
From: Wojtek Narczynski @ 2004-09-29 22:42 UTC (permalink / raw)


Hello,

I've tried to produce a patch for GNAT for this. Of curse, I realize what
"Standard" means, but I wanted to have this functionality (-gnatX
controlled) in order to deliver new arguments, by exposing all the tricks
caused by the absence of this feature. I believe this is the only way to
put this discussion back on (technical) track.

The Ada part was surprisingly easy, I only had to comment-out two lines.
After that it worked for types passed by reference. But for types passed
by copy, it turned out that modifications to GiGi C code are necessary.
But this code is in flux now (due to gcc tree-ssa change), so I left it
for now.

Regards,
Wojtek



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

* Re: why only in-parameters in functions
  2004-09-29 21:10   ` Randy Brukardt
@ 2004-09-29 23:37     ` Björn Persson
  2004-09-29 23:46       ` Rick Santa-Cruz
  0 siblings, 1 reply; 10+ messages in thread
From: Björn Persson @ 2004-09-29 23:37 UTC (permalink / raw)


Randy Brukardt wrote:

> The most recent go-round is saved in AI-323.

I bet Rick has no idea what AI-323 is.

http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00323.TXT?rev=1.2

-- 
Björn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu




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

* Re: why only in-parameters in functions
  2004-09-29 23:37     ` Björn Persson
@ 2004-09-29 23:46       ` Rick Santa-Cruz
  0 siblings, 0 replies; 10+ messages in thread
From: Rick Santa-Cruz @ 2004-09-29 23:46 UTC (permalink / raw)


Hi,

>I bet Rick has no idea what AI-323 is.
>
>http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00323.TXT?rev=1.2
Yes ;). Thanks.





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

* Re: why only in-parameters in functions
  2004-09-29 16:55 ` Alexander E. Kopilovich
                     ` (2 preceding siblings ...)
  2004-09-29 22:42   ` Wojtek Narczynski
@ 2004-09-30  1:55   ` Matthew Heaney
  3 siblings, 0 replies; 10+ messages in thread
From: Matthew Heaney @ 2004-09-30  1:55 UTC (permalink / raw)


"Alexander E. Kopilovich" <aek@VB1162.spb.edu> writes:

> In practice, where you really need in-parameters for a function you
> may either use a procedure that returns value (if you use GNAT
> compiler) or you may use the construct, presented here in c.l.a by
> Robert I. Eachus (see his message in comp.lang.ada from 2003-07-15
> with Subject: Re: What evil would happen?)
> 
> ----------------------------------------------------------------------------
> 
> function Random(Gen: in Generator) return ...
>    Local: Generator;
>    for Local'Address use Gen'Address;
> begin
>    ...
> end Random;
> 
> ----------------------------------------------------------------------------


Actually, if the type is limited, then you can use the Rosen Trick,
which is somewhat cleaner:

private

   type Handle (G : access Generator) is 
      limited null record;

   type Generator is limited record
      H : Handle (Generator'Access);
      ... -- rest of state
   end record;

end;

   function Random (G : Generator) return ...
      GG : Generator renames G.H.G.all;
   begin
      ... -- modify GG as desired
   end Radom;

The Rosen Trick was discovered in the fall of 1999.  See CLA archives
around that time for more info.



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

* Re: why only in-parameters in functions
  2004-09-29 21:12   ` Florian Weimer
@ 2004-09-30  7:41     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-30  7:41 UTC (permalink / raw)


On Wed, 29 Sep 2004 23:12:41 +0200, Florian Weimer wrote:

> The "Rosen trick" is also relevant in this context (see the archives),
> but it only works for limited types.  However, it should be used
> whenever possible because it does not involve erroneous execution.

Yes. However, using Rosen trick with derived types could face problems.
When an function (primitive operation) has to be overridden, then to access
the argument to be modified, one should either cast (bad) or dispatch
(assuming that the self-pointer is class-wide.) I.e. in fact, the function
is class-wide, though declared as a primitive one. It is not good, not a
clean design.

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



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

end of thread, other threads:[~2004-09-30  7:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-29 15:18 why only in-parameters in functions Rick Santa-Cruz
2004-09-29 15:30 ` stephane richard
2004-09-29 16:55 ` Alexander E. Kopilovich
2004-09-29 21:10   ` Randy Brukardt
2004-09-29 23:37     ` Björn Persson
2004-09-29 23:46       ` Rick Santa-Cruz
2004-09-29 21:12   ` Florian Weimer
2004-09-30  7:41     ` Dmitry A. Kazakov
2004-09-29 22:42   ` Wojtek Narczynski
2004-09-30  1:55   ` Matthew Heaney

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