Jump to content

Call a function: Difference between revisions

FutureBasic solution added
(Add Ecstasy example)
(FutureBasic solution added)
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>.
This is the default.
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Line 2,462 ⟶ 2,463:
 
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}}==
'''[https://gambas-playground.proko.eu/?gist=1bbbeb240f6fbca4b893271f1a19833b Click this link to run this code]'''<br>
Line 2,496 ⟶ 2,565:
Hello Hello Hello!!
</pre>
 
 
 
=={{header|Go}}==
The following examples use functions from the standard packages
Line 2,562 ⟶ 2,634:
bar(args["a"], args["b"], args["c"]) // prt 3, 2, 1
}</syntaxhighlight>
 
* 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>
Line 2,636 ⟶ 2,709:
fmt.Println(partial(5)) //prt 18
}</syntaxhighlight>
 
 
=={{header|Groovy}}==
There are two types of first-class functions in Groovy.
416

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.