Ada Function vs Procedure [closed]
Asked Answered
K

1

18

Can anyone explain me the difference between the Ada "procedure" and "function"?

Knowable answered 5/4, 2013 at 14:53 Comment(9)
@KeithThompson: Thanks for the reply. Unfortunately, I have 24 hours to do whatever :).Knowable
Well, function returns a value, and procedure does not. Pascal language for instance has the same. C-like languages have only functions, that can pretend being procedures by returning a void value. BTW, 24h is way enough to learn that kind of stuff :)Beforetime
@Archie: hmm, Thank you :) I thought it is different in Ada, because I saw everyting is different including for loops (you know, there is a 'range' loop, which is not a for loop). Do you mind providing the comment as an answer?Knowable
A procedure is an abstraction over a statement, while a function is an abstraction over an expression.Countershading
To the people who closed the question: that's actually a question, and a question which makes sense. I will reply in a comment as answers are now closed. Prior to Ada 2012, function could only have in‑mode parameters, while procedure could have all in, out and in‑out. Since Ada 2012, function are now allowed to have out and in‑out parameters. Still applying to Ada 2012, function can be applied the pragma Pure, while procedure can't. If only the people who voted to close the question knew at least a bit of Ada…Layout
This question is actually a duplicate.Lor
If it's a duplicate please include the link to the original question. This answer helped me immensely, as Ada is used frequently by US military applications. Also, anyone learning Ada will understand this question immediately, so this question serves its purpose in educating members.Rheotaxis
@Rheotaxis the link to duplicate is already mentioned there, as an inline linkAsthenic
@andrew-t: Sure, but when closed the reason should have been given as "duplicate" and not "closed as not a real question" because this question is very real for anyone exploring the world beyond mainstream programming languages.Rheotaxis
B
16

Ada language is not very much different comparing to other imperative C-like languages. The syntax though may look very strange and overwhelmed with different statements, but this is mainly because of a very rich static typing system and features directly provided by language (like tasks for example), that other languages provide as side libraries.

Unlike most of C-like languages, Ada distinguishes procedural and functional routines. In this sense function is very much as mathematical function that takes arguments (or none) and returns a value, and thus is used in expressions. Procedures do not return any values and cannot be used in expressions. Pascal language keeps the same distinction between functions and procedures. C-like languages chose to have just functions that can be used outside expressions (returned value is ignored in this case) or return a void value to act like a procedure.

Beforetime answered 5/4, 2013 at 18:58 Comment(2)
Can Ada procedures modify variables (change state)?Rheotaxis
Yes, procedures can change state with in out parameters.Rolland

© 2022 - 2024 — McMap. All rights reserved.