Function definition: Difference between revisions

Line 1,036:
 
=={{header|Delphi}}==
In addition to what is shown in the section [[#Pascal|Pascal]], the following is possible too:
<lang Delphidelphi>function Multiplymultiply(a, b: Integerinteger): Integerinteger;
begin
Resultresult := a * b;
end;</lang>
 
Line 1,379 ⟶ 1,380:
 
<lang freebasic>#Define multiply(d1, d2) (d1) * (d2)</lang>
 
=={{header|Free Pascal}}==
Free Pascal allows everything what [[#Delphi|Delphi]] allows.
Note, using the special variable “<tt>result</tt>” requires <tt>{$modeSwitch result+}</tt>.
This is the default in <tt>{$mode objFPC}</tt> and <tt>{$mode Delphi}</tt>.
 
Furthermore, after the assignment to the return variable further statements may follow.
To ensure a value is returned immediately and no further following statements are processed, using the built-in <tt>exit</tt> procedure is possible too in <tt>{$mode objFPC}</tt>:
<lang pascaldelphi>function multiply(a, b: realinteger): realinteger;
begin
exit(a * b);
end;</lang>
If <tt>exit</tt> has been redefined in the current scope, its special meaning can be accessed via the fully-qualified identifier <tt>system.exit</tt>.
Note, any enclosing <tt>finally</tt> frames of <tt>try … finally … end</tt> are processed first before actually returning from the <tt>function</tt>.
As a consequence of that, <tt>exit</tt> may not appear within a <tt>finally</tt> frame.
 
=={{header|Frink}}==
Line 2,421 ⟶ 2,437:
 
=={{header|Pascal}}==
''see also: [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''
(all versions and dialects)
 
<lang pascal>function multiply(a,b: real): real;
<lang pascal>function multiply(a, b: real): real;
begin
multiply := a * b;
end;</lang>
After a <tt>function</tt> has been activated, there must have be ''exactly one'' assignment to the (implicitly declared) variable bearing the same name as of the function.
Many processors do not comply with this specification, though, and allow ''overwriting'' the return value ''multiple'' times.
 
=={{header|Perl}}==
149

edits