comp.lang.ada
 help / color / mirror / Atom feed
[parent not found: <uhdyhq1zl.fsf@acm.org>]
* RE: In-Out Parameters for functions
@ 2004-01-23 15:59 amado.alves
  2004-01-23 18:02 ` Jean-Pierre Rosen
  0 siblings, 1 reply; 203+ messages in thread
From: amado.alves @ 2004-01-23 15:59 UTC (permalink / raw)
  To: comp.lang.ada

"I don't follow, and I would like to, because I find [IN] OUT params
for functions very useful. Could you please elaborate on that a bit
more?"
Maybe the most common example is the idiom (illegal in Ada):
  while Next (Item) loop
    Do_Something (Item);
  end loop;
where the Next function returns false in no more items are available,
and Item is an (illegal) in out parameter which holds the result of
a 'successful' call (and holds garbage on unsuccessful calls--this is 
the ugly bit). The above idiom is perhaps the most clean solution for
the associated problem. I know I invariably use it when I write in C.
(Sorry for the possibly illformatted text. 
I'm stuck with a crapy webmail system.)



^ permalink raw reply	[flat|nested] 203+ messages in thread
* Re: In-Out Parameters for functions (was: Re: Certified C compilers for safety-critical embedded systems
@ 2004-01-09 22:30 Robert A Duff
  2004-01-09 23:38 ` Alexandre E. Kopilovitch
  0 siblings, 1 reply; 203+ messages in thread
From: Robert A Duff @ 2004-01-09 22:30 UTC (permalink / raw)


Marin David Condic <nobody@noplace.com> writes:

> Yeah, but as far as I can tell C always had "in only" parameters and
> everything was a function returning a result. The only way you could get
> "in out" mode was passing addresses (indistinguishable to the garden
> variety programmer from a 'Access) and of course dealing with all the
> errors that resulted from no checking that a parameter actually was an
> address. Such a setup didn't seem to hurt C with respect to popularity
> or getting Fortran programmers to understand it.

I've heard a lot of Fortran programmers complaining about C!

> I'm ambivalent about "in out" for functions. I've never found it
> difficult to use functions just the way they are and can't think of a
> case where in-out would have helped me with a real world problem. The
> only example anyone ever seems to cite is the Random Number Generator
> leading me to think that maybe this *is* the only instance in which it
> is genuinely useful.

It's a good example because it's familiar -- it's in the RM.

I can think of several other examples.  How about this one:

    function Get_Line(F: in out File) return String;

You can't make that a procedure, because Get_Line itself needs to
determine the length of the result, and 'out' parameters don't work that
way.  And even if they did, it's kind of nice to be able to say:

    X: constant String := Get_Line(F);

>... OTOH, I could see how they might be included and
> not impact my life one iota. If you don't need it, you don't use
> it.

I agree with that philosophy.  It is not the job of the language
designer to prevent people from doing evil things.  It is the job of the
language designer to prevent people from doing evil things *by
accident*.  You're not likely to declare 'in out' parameters by
accident, so it's fine to let the programmer decide when to use it.
(Probably not very often -- *most* functions should be free of side
effects.)

Except, as you say:

>... Except that possibly it casts into doubt what happens in an
> expression loaded with function calls where one used to be able to
> assume that the parameters were not being modified. With in-out you'd
> have to know the parameter modes before you could interpret what the
> expression was doing.

That's a good point, too.  You can't get any advantage out of having
side-effect-free functions unless you (the reader of the program) can
somehow *know* that they are side-effect-free.

I would be in favor of marking 'in out' and 'out' with some syntax at
the call site.  I would also be in favor of marking calls syntactically
if they have side effects on global variables.  But none of that has
anything to do with Ada (although there was an *optional* way to mark
'[in] out' in Green).

> MDC
> 
> Robert A Duff wrote:
> > As far as I can remember, this idea was considered, and was generally
> > thought to be ugly.  I mean, suppose you're trying to convince a Fortran
> > programmer to use Ada for numerics stuff.  If you start babbling about
> > aliased and 'Access when there is no inherent need for pointers,
> > they're going to laugh, and rightly so.

A: So I know what you're talking about without looking ahead.
Q: Why is top-posting a bad idea?
;-)

- Bob



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

end of thread, other threads:[~2004-03-04  0:08 UTC | newest]

Thread overview: 203+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <un089585d.fsf@acm.org>
2004-01-27 23:45 ` In-Out Parameters for functions Alexandre E. Kopilovitch
     [not found] ` <iSYWl50LxF@VB1162.spb.edu>
2004-01-28  2:53   ` Stephen Leake
     [not found] <uhdyhq1zl.fsf@acm.org>
2004-01-27 20:48 ` Alexandre E. Kopilovitch
2004-01-27 21:09   ` Hyman Rosen
2004-01-28  0:09     ` Alexandre E. Kopilovitch
2004-01-28  0:42       ` Hyman Rosen
2004-01-28 10:16   ` Dmitry A. Kazakov
     [not found] ` <iSwwi50LxF@VB1162.spb.edu>
2004-01-27 22:38   ` Stephen Leake
2004-01-23 15:59 amado.alves
2004-01-23 18:02 ` Jean-Pierre Rosen
  -- strict thread matches above, loose matches on Subject: below --
2004-01-09 22:30 In-Out Parameters for functions (was: Re: Certified C compilers for safety-critical embedded systems Robert A Duff
2004-01-09 23:38 ` Alexandre E. Kopilovitch
2004-01-23 14:01   ` In-Out Parameters for functions Wojtek Narczynski
2004-01-23 19:05     ` Alexandre E. Kopilovitch
2004-01-24 15:21       ` Wojtek Narczynski
2004-01-24 20:42         ` Alexandre E. Kopilovitch
2004-01-24 21:57           ` Robert A Duff
2004-01-25 21:02             ` Alexandre E. Kopilovitch
2004-01-26 10:17               ` Dmitry A. Kazakov
2004-01-26 20:19                 ` Alexandre E. Kopilovitch
2004-01-27  9:22                   ` Dmitry A. Kazakov
2004-01-26 14:06               ` Wojtek Narczynski
2004-01-26 19:00                 ` Alexandre E. Kopilovitch
2004-01-27 10:24                   ` Wojtek Narczynski
2004-01-26 20:38                 ` Robert A Duff
2004-01-27 10:45                   ` Wojtek Narczynski
2004-01-26 23:12               ` Robert A Duff
2004-01-26 23:24                 ` Hyman Rosen
2004-01-26 23:37                   ` Robert A Duff
2004-01-27  2:26                     ` Hyman Rosen
2004-01-27  8:18                       ` Stephen Leake
2004-01-27 17:37                         ` Hyman Rosen
2004-01-27 19:05                           ` David Starner
2004-01-27 19:31                             ` Hyman Rosen
2004-01-27 20:06                           ` Robert A Duff
2004-01-28  9:29                             ` Dmitry A. Kazakov
2004-01-28 15:20                               ` Hyman Rosen
2004-01-29  9:08                                 ` Dmitry A. Kazakov
2004-01-29 15:37                                   ` Hyman Rosen
2004-01-29 18:43                                     ` David Starner
2004-01-29 19:46                                       ` Hyman Rosen
2004-01-29 20:23                                         ` Georg Bauhaus
2004-01-29 21:36                                           ` Hyman Rosen
2004-01-30 17:39                                             ` Georg Bauhaus
2004-01-30 18:14                                               ` Hyman Rosen
2004-01-30 19:32                                                 ` Georg Bauhaus
2004-01-30 20:51                                                   ` Hyman Rosen
2004-01-30 23:25                                                     ` Georg Bauhaus
2004-01-31  0:07                                                     ` Robert I. Eachus
2004-01-29 23:52                                         ` David Starner
2004-01-30  3:02                                         ` Robert I. Eachus
2004-01-30 16:09                                           ` Hyman Rosen
2004-01-30 16:31                                             ` Peter Amey
2004-01-30 19:20                                               ` Hyman Rosen
2004-02-02 10:39                                                 ` Peter Amey
2004-01-31  1:03                                             ` Robert I. Eachus
2004-01-30  9:53                                         ` Dmitry A. Kazakov
2004-01-30 17:06                                           ` Hyman Rosen
2004-01-30 17:52                                             ` David Starner
2004-01-30 20:28                                               ` Hyman Rosen
2004-01-30 21:31                                             ` Alexandre E. Kopilovitch
2004-02-01  4:10                                               ` Hyman Rosen
2004-02-01 21:05                                                 ` David Starner
2004-02-01 21:55                                                   ` Hyman Rosen
2004-02-02  2:20                                                     ` David Starner
2004-02-02 14:36                                                       ` Hyman Rosen
2004-01-31  5:27                                             ` Randy Brukardt
2004-02-01  4:02                                               ` Hyman Rosen
2004-02-03  1:54                                                 ` Randy Brukardt
2004-02-03  3:07                                                   ` Hyman Rosen
2004-02-01  2:14                                             ` cl1motorsports
2004-02-02  9:31                                             ` Dmitry A. Kazakov
2004-02-02 14:33                                               ` Hyman Rosen
2004-02-02 15:41                                                 ` Dmitry A. Kazakov
2004-02-02 17:01                                                   ` Hyman Rosen
2004-02-03  8:54                                                     ` Dmitry A. Kazakov
2004-02-03 14:06                                                       ` Hyman Rosen
2004-02-03 15:32                                                         ` Dmitry A. Kazakov
2004-02-03 16:11                                                           ` Hyman Rosen
2004-02-03 23:04                                                             ` David Starner
2004-02-03 23:38                                                               ` Hyman Rosen
2004-02-04  1:54                                                                 ` David Starner
2004-02-04 14:54                                                                   ` Hyman Rosen
2004-02-04  3:56                                                                 ` Alexandre E. Kopilovitch
2004-02-05 13:32                                                                   ` Hyman Rosen
2004-02-04  7:00                                                                 ` Vinzent 'Gadget' Hoefler
2004-02-04 14:57                                                                   ` Hyman Rosen
2004-02-04 15:19                                                                     ` Vinzent 'Gadget' Hoefler
2004-02-04 15:52                                                                       ` Hyman Rosen
2004-02-04 16:36                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-04 17:11                                                                           ` Hyman Rosen
2004-02-04 19:58                                                                         ` David Starner
2004-02-04 10:28                                                                 ` Stuart Palin
2004-02-04 15:07                                                                   ` Hyman Rosen
2004-02-04 15:19                                                                     ` Vinzent 'Gadget' Hoefler
2004-02-04 15:54                                                                       ` Hyman Rosen
2004-02-04 16:36                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-04 17:13                                                                           ` Hyman Rosen
2004-02-05 12:11                                                                     ` Stuart Palin
2004-02-05 13:22                                                                       ` Hyman Rosen
2004-02-05 14:53                                                                         ` Robert I. Eachus
2004-02-05 15:43                                                                           ` Hyman Rosen
2004-02-06  7:41                                                                             ` Robert I. Eachus
2004-02-24  1:27                                                                               ` Hyman Rosen
2004-02-06 10:27                                                                         ` Stuart Palin
2004-02-24  1:55                                                                           ` Hyman Rosen
2004-02-24  2:16                                                                             ` David Starner
2004-02-24 14:51                                                                               ` Hyman Rosen
2004-02-24 23:55                                                                                 ` David Starner
2004-02-25  0:44                                                                                   ` Stephen Leake
2004-02-25  9:21                                                                                     ` Dmitry A. Kazakov
2004-02-25  9:33                                                                                     ` David Starner
2004-02-25 14:21                                                                                       ` Hyman Rosen
2004-02-25 14:34                                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-25 15:02                                                                                           ` Hyman Rosen
2004-02-25 15:43                                                                                             ` Vinzent 'Gadget' Hoefler
2004-02-25 15:53                                                                                               ` Hyman Rosen
2004-02-25 16:05                                                                                                 ` Vinzent 'Gadget' Hoefler
2004-02-25 16:44                                                                                                   ` Hyman Rosen
2004-02-25 20:45                                                                                                     ` Randy Brukardt
2004-02-25 21:33                                                                                                       ` Hyman Rosen
2004-02-26  8:45                                                                                                         ` Preben Randhol
2004-02-26  8:46                                                                                                           ` Preben Randhol
2004-02-26 14:41                                                                                                           ` Hyman Rosen
2004-02-26  9:44                                                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-26 13:24                                                                                                           ` Robert I. Eachus
2004-02-26 14:33                                                                                                             ` Jean-Pierre Rosen
2004-02-28 17:11                                                                                                               ` Robert I. Eachus
2004-02-26 15:21                                                                                                             ` Hyman Rosen
2004-02-27  5:21                                                                                                             ` Stephen Leake
2004-02-27  8:55                                                                                                               ` David Starner
2004-02-26  9:44                                                                                                     ` Vinzent 'Gadget' Hoefler
2004-02-26 15:24                                                                                                       ` Hyman Rosen
2004-02-26 17:33                                                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-25 16:34                                                                                                 ` Preben Randhol
2004-02-25 16:45                                                                                                   ` Hyman Rosen
2004-02-25 18:37                                                                                                     ` Frank J. Lhota
2004-02-26 13:29                                                                                                     ` Robert I. Eachus
2004-02-25 16:35                                                                                                 ` Preben Randhol
2004-02-25 16:56                                                                                                   ` Hyman Rosen
2004-02-25 17:11                                                                                                     ` Preben Randhol
2004-02-25 17:33                                                                                                       ` Hyman Rosen
2004-02-25 15:44                                                                                             ` Hyman Rosen
2004-02-25 16:10                                                                                             ` Robert I. Eachus
2004-02-25 16:50                                                                                               ` Hyman Rosen
2004-02-26 13:41                                                                                                 ` Robert I. Eachus
2004-02-26 15:44                                                                                                   ` Hyman Rosen
2004-02-28 17:34                                                                                                     ` Robert I. Eachus
2004-02-29  3:51                                                                                                       ` Hyman Rosen
2004-02-29 14:10                                                                                                         ` Robert I. Eachus
2004-02-29 15:37                                                                                                           ` Jon S. Anthony
2004-03-01 17:38                                                                                                           ` Hyman Rosen
2004-03-02  3:05                                                                                                             ` Robert I. Eachus
2004-03-02  7:08                                                                                                               ` Hyman Rosen
2004-03-02  8:48                                                                                                                 ` Jacob Sparre Andersen
2004-03-02 15:24                                                                                                                   ` Hyman Rosen
2004-03-02 15:42                                                                                                                     ` Jacob Sparre Andersen
2004-03-02 16:33                                                                                                                       ` Hyman Rosen
2004-03-02 22:06                                                                                                                         ` Robert I. Eachus
2004-03-02 22:43                                                                                                                         ` Randy Brukardt
2004-03-02 17:12                                                                                                                 ` Robert I. Eachus
2004-03-02 17:28                                                                                                                   ` Georg Bauhaus
2004-03-02 22:09                                                                                                                     ` Robert I. Eachus
2004-03-04  0:08                                                                                                                       ` Georg Bauhaus
2004-02-27  5:31                                                                                               ` Stephen Leake
2004-02-25 12:01                                                                                     ` Marin David Condic
2004-02-25 20:41                                                                                     ` Randy Brukardt
2004-02-25 22:05                                                                                     ` Jim Rogers
2004-02-25 22:19                                                                                       ` Hyman Rosen
2004-02-26  9:34                                                                                         ` Dmitry A. Kazakov
2004-02-26  9:44                                                                                         ` Vinzent 'Gadget' Hoefler
2004-02-26 15:48                                                                                           ` Hyman Rosen
2004-02-26 17:49                                                                                             ` Vinzent 'Gadget' Hoefler
2004-02-26 18:12                                                                                               ` Hyman Rosen
2004-02-27  0:55                                                                                                 ` David Starner
2004-02-27 23:37                                                                                           ` Randy Brukardt
2004-02-26 12:42                                                                                         ` Wojtek Narczynski
2004-02-26 12:47                                                                                           ` Lutz Donnerhacke
2004-02-26 15:56                                                                                             ` Hyman Rosen
2004-02-26 13:50                                                                                         ` Robert I. Eachus
2004-02-26 16:00                                                                                           ` Hyman Rosen
2004-02-28 17:48                                                                                             ` Robert I. Eachus
2004-02-27  6:00                                                                                           ` Stephen Leake
2004-02-28 18:18                                                                                             ` Robert I. Eachus
2004-02-24  8:22                                                                             ` Jacob Sparre Andersen
2004-02-24  9:31                                                                               ` Jean-Pierre Rosen
2004-02-04  3:01                                                         ` Alexandre E. Kopilovitch
2004-02-04  3:26                                                           ` Ludovic Brenta
2004-02-04  9:40                                                             ` Dmitry A. Kazakov
2004-01-27  9:36                       ` Dmitry A. Kazakov
2004-01-27 12:45                         ` Georg Bauhaus
2004-01-27  1:12                 ` Alexandre E. Kopilovitch
2004-01-27  9:23           ` Peter Amey
2004-01-27 17:24             ` Robert A Duff
2004-01-28 10:30               ` Wojtek Narczynski
2004-01-28 20:39                 ` Robert A Duff
2004-01-28 23:13                   ` Randy Brukardt
2004-01-29  9:20                     ` Dmitry A. Kazakov
2004-01-29 23:30                       ` Randy Brukardt
2004-01-30 23:39                       ` Alexandre E. Kopilovitch
2004-02-02  9:38                         ` Dmitry A. Kazakov
2004-01-29 12:22                     ` Wojtek Narczynski
2004-01-29 20:25                       ` Alexandre E. Kopilovitch
2004-01-29 11:08                 ` Peter Amey
     [not found]         ` <dSgYj40LxF@VB1162.spb.edu>
2004-01-27  7:34           ` Stephen Leake

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