Oxygen Basic
Programming => Example Code => General => Topic started by: Charles Pegge on February 01, 2018, 07:11:18 PM
-
Using Oxygen.dll in OxygenProgress.zip and OxygenBasicProgress.zip (1 Feb 2018)
https://github.com/Charles-Pegge/OxygenBasic
This example demontrates the flexibility gained by specifying default params:
uses MinWin
'
macro msgbox(hwnd=0, text="?", title="OxygenBasic", type=0)
MessageBox(hwnd,text,title,type)
end macro
'
msgbox 0,"text","title",1
msgbox
msgbox 0,"Hello World"
msgbox text="Hello World", type=2
-
Hi Charles,
I will stay with the Latest Alpha at least for the next two months. But this macro feature induced me to create an OxygenBeta folder, install Oxygen in progress and use my little O2HEdit project with it. As this works I can see the different behaviour of the two versions better now.
The possibility of using macros with default params is indeed impressive. I could not resist and tried this variation:
msgbox type=MB_OKCANCEL|MB_ICONQUESTION, text="Hello World"
and it works! This is amazing. Does Oxygenbasic show initiative and think for itself?
Roland
-
Does Oxygenbasic show initiative and think for itself?
Yes! Especially when eliminating excess code in the compiler. Repeating patterns become visible, and new features emerge :)
-
Hi Charles,
in folder tests\constructs there is the file MultiDimArray.o2bas which does not work with the new oxygen.dlls. I think this is because of the new macro rules. If I use:
...
macro bm(z,y,x, xe,ye,ze) b[z*xe*ye+y*xe+x]
...
then I will get the expected result. It will also work if I use:
...
macro bm(z,y,x, ,xe,ye,ze) b[z*xe*ye+y*xe+x]
...
What is the difference between using , xe and , ,xe? With the new macro system (e.g. #return) would there be altenatives for treating multidimensional arrays?
Roland
-
Hi Roland.
Macro prototypes are currently very lax concerning delimiters. Commas are ignored except when specifying default parameters.
no commas!
macro m(a b c d){print a+b+c+d}
print m 1,2,3,4
commas required with default params:
macro m(a=1, b=2, c=3, d=4){print a+b+c+d}
print m 100
I need to edit test/constructs since a number of them are obsolete.
-
This simple example demonstrates default params in a macro function
'2018-05-03 T 17:29:09
'default params
'
macro mm int(r,a=1,b=2,c=4,d=8, s,t)
====================================
r=a+b+c+d
end macro
'
'TESTS
======
'#recordof mm
print mm(10,20,40,80)
print mm
print mm()
print mm(11)
print mm(d=108)
print mm(a=1001,d=108)