First-class functions/Use numbers analogously: Difference between revisions
Content added Content deleted
imported>Arakov |
(Added FreeBASIC) |
||
Line 565: | Line 565: | ||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
|||
FreeBASIC does not support first-class functions or function closures, which means that you cannot create a function that returns another function or that has a function defined inside it. |
|||
However, similar behavior can be achieved with subroutines and global variables. |
|||
<syntaxhighlight lang="vbnet">Dim As Double x = 2.0, xi = 0.5 |
|||
Dim As Double y = 4.0, yi = 0.25 |
|||
Dim As Double z = x + y, zi = 1.0 / (x + y) |
|||
Dim As Double values(2) = {x, y, z} |
|||
Dim As Double inverses(2) = {xi, yi, zi} |
|||
Dim Shared As Double m = 0.5 |
|||
Function multiplier(a As Double, d As Double) As Double |
|||
Return a * d * m |
|||
End Function |
|||
For i As Byte = 0 To Ubound(values) |
|||
Dim As Double new_function = multiplier(values(i), inverses(i)) |
|||
Print values(i); " *"; inverses(i); " *"; m; " ="; new_function |
|||
Next i |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 2 * 0.5 * 0.5 = 0.5 |
|||
4 * 0.25 * 0.5 = 0.5 |
|||
6 * 0.1666666666666667 * 0.5 = 0.5</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |