Author Topic: Default parameters in macros  (Read 114 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Author
  • *****
  • Posts: 3365
    • Oxygen Basic
Default parameters in macros
« 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:

Code: [Select]
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

Arnold

  • Hero Member
  • *****
  • Posts: 510
Re: Default parameters in macros
« Reply #1 on: February 02, 2018, 04:34:01 AM »
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
« Last Edit: February 02, 2018, 04:56:33 AM by Arnold »

Charles Pegge

  • Author
  • *****
  • Posts: 3365
    • Oxygen Basic
Re: Default parameters in macros
« Reply #2 on: February 03, 2018, 06:58:55 AM »
Quote
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 :)

Arnold

  • Hero Member
  • *****
  • Posts: 510
Re: Default parameters in macros
« Reply #3 on: February 12, 2018, 12:42:01 AM »
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

Charles Pegge

  • Author
  • *****
  • Posts: 3365
    • Oxygen Basic
Re: Default parameters in macros
« Reply #4 on: February 12, 2018, 03:31:59 AM »
Hi Roland.

Macro prototypes are currently very lax concerning delimiters. Commas are ignored except when specifying default parameters.

no commas!
Code: [Select]
macro m(a b c d){print a+b+c+d}
print m 1,2,3,4

commas required with default params:
Code: [Select]
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.