This shows you the differences between two versions of the page.
returning_20an_20array_20from_20a_20function [2018/03/31 14:19] 127.0.0.1 external edit |
returning_20an_20array_20from_20a_20function [2018/04/17 19:32] tbest3112 Added syntax highlighting |
||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, November 2012//\\ \\ Modifying the // | //by Richard Russell, November 2012//\\ \\ Modifying the // | ||
+ | <code bb4w> | ||
DEF PROCidn(RETURN i(), n%) | DEF PROCidn(RETURN i(), n%) | ||
LOCAL i% | LOCAL i% | ||
Line 9: | Line 10: | ||
NEXT | NEXT | ||
ENDPROC | ENDPROC | ||
+ | </ | ||
The procedure is called with two parameters: the array to be created (which must not have been previously dimensioned) and the required size (maximum row and column index), for example: | The procedure is called with two parameters: the array to be created (which must not have been previously dimensioned) and the required size (maximum row and column index), for example: | ||
+ | <code bb4w> | ||
PROCidn(identity(), | PROCidn(identity(), | ||
+ | </ | ||
This works well, but in one respect it is not particularly ' | This works well, but in one respect it is not particularly ' | ||
+ | <code bb4w> | ||
result = FNfunction(parameters) | result = FNfunction(parameters) | ||
+ | </ | ||
Wouldn' | Wouldn' | ||
+ | <code bb4w> | ||
DEF FNidn(n%) | DEF FNidn(n%) | ||
LOCAL i%, !^i() | LOCAL i%, !^i() | ||
Line 21: | Line 28: | ||
NEXT | NEXT | ||
= !^i() | = !^i() | ||
+ | </ | ||
Note particularly the use of **!^** in both the LOCAL statement and when the array is returned from the function. The function can then be called as follows: | Note particularly the use of **!^** in both the LOCAL statement and when the array is returned from the function. The function can then be called as follows: | ||
+ | <code bb4w> | ||
!^identity() = FNidn(3) | !^identity() = FNidn(3) | ||
+ | </ | ||
Again, note the use of an //array pointer// using **!^**.\\ \\ This may be a useful technique when translating from a language that can directly return an array from a function, or simply to create a more elegant code solution. | Again, note the use of an //array pointer// using **!^**.\\ \\ This may be a useful technique when translating from a language that can directly return an array from a function, or simply to create a more elegant code solution. |