From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Procedure vs function Date: Sat, 06 Sep 2014 08:44:35 +0300 Organization: Tidorum Ltd Message-ID: References: <9032a6f8-57ea-490c-bab0-2d0624eede00@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net bnqkNLUDFlrRfG0D6E1Rag0zYa/ZdOJiSIwSOEx92m2U0RrdIz Cancel-Lock: sha1:y57MGsIm90ZoXTxrl4x6qULWa2c= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <9032a6f8-57ea-490c-bab0-2d0624eede00@googlegroups.com> Xref: number.nntp.dca.giganews.com comp.lang.ada:188891 Date: 2014-09-06T08:44:35+03:00 List-Id: On 14-09-06 05:19 , Stribor40 wrote: > Would anyone please try to explain difference between procedure and > function. Some online material describes procedure as of series > of declaration and algoritmic code and function is something that > returns data type. Does this mean that procedure can be within > the scope of function perhaps body of the procedure inside the > body of function? > > Any info or simple example would be appreciated See http://en.wikibooks.org/wiki/Ada_Programming/Subprograms. 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 " 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. A procedure call does not return a value and therefore can be used only as a statement of its own, not within an expression. The effect of the procedure call is to assign values to its "out" and "in out" parameters and perhaps to other variables to which the procedure has access. Function calls can also have such effects, in addition to returning a value. Example: function Square (X : Float) return Float is begin return X * X; end Square; Then it is possible to write the expression Square(A) + Square(B), where A and B are some Float expressions, and the result is the sum of the squares of A and B. The same could be written as a procedure: procedure Compute_Square (X : in Float; Y : out Float) is begin Y := X * X; end Compute_Square; Now, to compute the sum of the squares of A and B, some auxiliary variables Sq_A, Sq_B and two statements are needed: Compute_Square (X => A, Y => Sq_A); Compute_Square (X => B, Y => Sq_B); and then you can write Sq_A + Sq_B for the sum of the squares of A and B. Typically, procedures are used for computations that return several results (in the "out" and "in out" parameters) or have significant side effects on other data. Functions are typically used to compute a single new value from the function's parameters, where the computation has no significant side effects. But these are just design conventions. Subprograms of any kind can be nested within other subprograms, whether the subprograms are functions or procedures. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .