Oxygen Basic
Programming => Example Code => General => Topic started by: Charles Pegge on October 22, 2014, 09:38:48 PM
-
By using a macro which creates a scoped array in which to pass the data.
DataCall fun points( {"one",1,2,3},{"two",2,4,6} )
def DataCall
'%1 function name
'%2 variable type
'%3 data
scope
%2 d = { %3 }
%1 d, countof d
end scope
end def
include "$/inc/console.inc"
'indexbase 0
def DataCall
'%1 function name
'%2 variable type
'%3 data
scope
%2 d = { %3 }
%1 d, countof d
end scope
end def
type points
string name
double x,y,z
end type
function fun(Points*d, sys n)
for i=1 to n
printl d[i].name tab d[i].x tab d[i].y tab d[i].z
next
end function
'scope
'Points d= { {"one",1,2,3},{"two",2,4,6} } : fun d, countof d
'end scope
'using the macro:
DataCall fun points( {"one",1,2,3},{"two",2,4,6} )
waitkey
-
Nice find, Charles.
In FBSL, braces define an anonymous (i.e. nameless) array of temp Variant vars, and such function calls are possible without the use of a macro or UDT definition. The array would provide the usual LBound(), UBound() and Count() functionality, and GetType() would supply the type info about the array's constituent elements:
Sub Foo(a = {}, b = {})
If Count(a) Then Print a[0]
If UBound(b) Then Print b[0] + b[1]
End Sub
Foo({!1, !!2, %3, %%4, "five"}) // will print 1.000000 only, won't print anything for b[]
It's great to see minds working in parallel. Perhaps that's exactly why I came here, if anyone wondered. :)
-
Hi Mike,
Yes, that highlights the difference in statefulness between compiler and interpreter. Oxygen might benefit from a standard array object, and set of macros to manage data input, multidimensioning, redimesioning, UBOUND & LBOUND.
There are classes called StringArray and TextArray in inc/StringUtil.inc which can be deployed for line-based text. They do not depend on fixed-length arrays.