comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Procedure vs function
Date: Fri, 05 Sep 2014 23:25:40 -0700
Date: 2014-09-05T23:25:40-07:00	[thread overview]
Message-ID: <lue9d5$9kq$1@dont-email.me> (raw)
In-Reply-To: <c6vla4F90tsU1@mid.individual.net>

On 09/05/2014 10:44 PM, Niklas Holsti wrote:
> 
> In a nutshell: the only difference between a function subprogram and a
> procedure subprogram is that a function call returns a value, from a
> "return <expression>" statement inside the function, and therefore a
> function call can (and must) be used as part of an expression, not as a
> stand-alone statement.

Another significant difference is that the value returned from a function can
have constraints not known by the caller when the call is made, while any values
returned from procedures go into the actual parameters of "[in] out" parameters,
which must be variables, and hence have constraints imposed by the caller.

Compare the function and procedure versions of Ada.Text_IO.Get_Line. With the
function version

declare
   S : String := Ada.Text_IO.Get_Line;

S can have any length and the line terminator will always be skipped. With the
procedure version

declare
   S : String (1 .. N);
   L : Natural;
begin
   Ada.Text_IO.Get_Line (Item => S, Last => L);

S'Length = N. If the line contains more then N characters, only N will be placed
in S, and the line terminator will not be skipped.

-- 
Jeff Carter
"It's all right, Taggart. Just a man and a horse being hung out there."
Blazing Saddles
34


      reply	other threads:[~2014-09-06  6:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-06  2:19 Procedure vs function Stribor40
2014-09-06  5:44 ` Niklas Holsti
2014-09-06  6:25   ` Jeffrey Carter [this message]
replies disabled

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