Call a function: Difference between revisions

Content added Content deleted
(Add Ecstasy example)
(FutureBasic solution added)
Line 2,418: Line 2,418:
Note, calling a <tt>function</tt> as if it was a <tt>procedure</tt> [i. e. ''discarding'' the return value] is only permitted if you set the compiler setting <tt>{$extendedSyntax on}</tt>/<tt>{$X+}</tt>.
Note, calling a <tt>function</tt> as if it was a <tt>procedure</tt> [i. e. ''discarding'' the return value] is only permitted if you set the compiler setting <tt>{$extendedSyntax on}</tt>/<tt>{$X+}</tt>.
This is the default.
This is the default.

=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
<syntaxhighlight lang="freebasic">
Line 2,462: Line 2,463:


1, 2, 3, 4, cadena, 6, 7, 8, \'incluye texto\'</pre>
1, 2, 3, 4, cadena, 6, 7, 8, \'incluye texto\'</pre>

=={{header|FutureBasic}}==
No arguments
<syntaxhighlight lang="futurebasic">
void local fn MyFunction
print @"MyFunction"
end fn

fn MyFunction

HandleEvents
</syntaxhighlight>

Fixed arguments
<syntaxhighlight lang="futurebasic">
void local fn MyFunction( arg1 as long, arg2 as long, arg3 as long )
print @"MyFunction"
end fn

fn MyFunction( 1, 2, 3 )

HandleEvents
</syntaxhighlight>

Variable arguments
<syntaxhighlight lang="futurebasic">
void local fn MyFunction( count as long, ... )
va_list ap
long i, value
va_start( ap, count )
for i = 1 to count
value = fn va_arglong( ap )
print value
next
va_end( ap )
end fn

fn MyFunction( 3, 12, 24, 36 )

HandleEvents
</syntaxhighlight>

Return value
<syntaxhighlight lang="futurebasic">
local fn MultiplyByThree( value as long ) as long
end fn = value * 3

print fn MultiplyByThree( 13 )

HandleEvents
</syntaxhighlight>

Value by reference
<syntaxhighlight lang="futurebasic">
void local fn MultiplyByThree( value as ^long )
*value *= 3
end fn

long num
num = 9
fn MultiplyByThree( @num )
print num

HandleEvents
</syntaxhighlight>

=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=1bbbeb240f6fbca4b893271f1a19833b Click this link to run this code]'''<br>
'''[https://gambas-playground.proko.eu/?gist=1bbbeb240f6fbca4b893271f1a19833b Click this link to run this code]'''<br>
Line 2,496: Line 2,565:
Hello Hello Hello!!
Hello Hello Hello!!
</pre>
</pre>



=={{header|Go}}==
=={{header|Go}}==
The following examples use functions from the standard packages
The following examples use functions from the standard packages
Line 2,562: Line 2,634:
bar(args["a"], args["b"], args["c"]) // prt 3, 2, 1
bar(args["a"], args["b"], args["c"]) // prt 3, 2, 1
}</syntaxhighlight>
}</syntaxhighlight>

* Within a statement context.
* Within a statement context.
::Assignment statements are shown later. Only functions returning a single value can be used in a single value context: <syntaxhighlight lang="go"> if 2*g(1, 3.0)+4 > 0 {}</syntaxhighlight>
::Assignment statements are shown later. Only functions returning a single value can be used in a single value context: <syntaxhighlight lang="go"> if 2*g(1, 3.0)+4 > 0 {}</syntaxhighlight>
Line 2,636: Line 2,709:
fmt.Println(partial(5)) //prt 18
fmt.Println(partial(5)) //prt 18
}</syntaxhighlight>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
There are two types of first-class functions in Groovy.
There are two types of first-class functions in Groovy.