Call a function: Difference between revisions

Added BBC BASIC
(Added BBC BASIC)
Line 212:
goto :eof
</lang>
 
=={{header|BBC BASIC}}==
BBC BASIC distinguishes between functions (which return one value), procedures (which may return an arbitrary number of values including zero), and subroutines. Functions can be built-in or user-defined.
A call to a <b>built-in function</b> (for example, the square root function) is an expression:
<lang bbcbasic>PRINT SQR(2)</lang>
The parentheses can often be omitted:
<lang bbcbasic>PRINT SQR 2</lang>
The name of a <b>user-defined function</b> must begin with <tt>FN</tt>. A call to it is also an expression:
<lang bbcbasic>PRINT FN_foo(bar$, baz%)</lang>
(The sigils <tt>$</tt> and <tt>%</tt> identify the variables' types.)
A function that takes no arguments can be called omitting the parentheses:
<lang bbcbasic>PRINT FN_foo</lang>
The name of a <b>procedure</b> must begin with <tt>PROC</tt>. A call to it is a statement, not an expression:
<lang bbcbasic>PROC_foo</lang>
If it has arguments, they come in parentheses just as with a function:
<lang bbcbasic>PROC_foo(bar$, baz%, quux)</lang>
Note that you <i>cannot tell from this syntax</i> which of the variables <tt>bar$</tt>, <tt>baz%</tt>, and <tt>quux</tt> are arguments provided to the procedure and which of them are return values from it. You have to look at where it is defined:
<lang bbcbasic>DEF PROC_foo(a$, RETURN b%, RETURN c)</lang>
<b>Subroutines</b> are provided for compatibility with older, unstructured dialects of BASIC; otherwise they are never really used. They require statements to be numbered, and they can neither receive arguments nor return values: they can only manipulate global variables. The <tt>GOSUB</tt> and <tt>RETURN</tt> statements in fact mirror assembly language 'jump to subroutine' and 'return from subroutine' instructions quite closely.
<lang bbcbasic>200 GOSUB 30050</lang>
 
=={{header|Bracmat}}==
519

edits