Nested function: Difference between revisions
Content deleted Content added
Added Sidef |
Added FreeBASIC |
||
Line 199: | Line 199: | ||
F95 introduced facilities whereby a string-style compound variable with both content and current length could be defined and manipulated, and when assigned to it would be reallocated storage so as to have exactly the size to hold the result. Later fortran standardised such a scheme. Similarly, one could define a data aggregate containing a count <code>N</code> as well as the <code>TEXT</code> array and a function could return such a compound entity as its result. It may also be possible to arrange that array TEXT becomes "ragged", that is, TEXT(i) is not always 28 characters long, but only as much as is needed to store the actual item. |
F95 introduced facilities whereby a string-style compound variable with both content and current length could be defined and manipulated, and when assigned to it would be reallocated storage so as to have exactly the size to hold the result. Later fortran standardised such a scheme. Similarly, one could define a data aggregate containing a count <code>N</code> as well as the <code>TEXT</code> array and a function could return such a compound entity as its result. It may also be possible to arrange that array TEXT becomes "ragged", that is, TEXT(i) is not always 28 characters long, but only as much as is needed to store the actual item. |
||
=={{header|FreeBASIC}}== |
|||
FreeBASIC does not currently support either nested procedures or lambda expressions. |
|||
The best we can do here is to create two separate procedures but pass the state of the first procedure |
|||
by reference to the second procedure so it can be modified by the latter. |
|||
<lang freebasic>' FB 1.05.0 Win64 |
|||
Sub makeItem(sep As String, ByRef counter As Integer, text As String) |
|||
counter += 1 |
|||
Print counter; sep; text |
|||
End Sub |
|||
Sub makeList(sep As String) |
|||
Dim a(0 To 2) As String = {"first", "second", "third"} |
|||
Dim counter As Integer = 0 |
|||
While counter < 3 |
|||
makeItem(sep, counter, a(counter)) |
|||
Wend |
|||
End Sub |
|||
makeList ". " |
|||
Print |
|||
Print "Press any key to quit" |
|||
Sleep |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
1. first |
|||
2. second |
|||
3. third |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |