Author Topic: Variadic Macros  (Read 1996 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Variadic Macros
« on: February 04, 2015, 01:20:29 PM »
A very simple idea: the macro clones itself for every parameter passed.

  macro mi(...)
  printl ...
  end macro


  mi 1,2,3,4,5,6,7


result:
1
2
3
4
5
6
7



Oxygen Update
http://www.oxygenbasic.org/o2zips/Oxygen.zip

Charles Pegge

  • Guest
Re: Variadic macros and macros with optional parameters
« Reply #1 on: February 04, 2015, 01:27:55 PM »
Another concept to allow macros to process optional parameters:

#ifexist
#ifnexist


Code: OxygenBasic
  1.  
  2.   includepath "$/inc/"
  3.   include "console.inc"
  4.  
  5.   macro mo(a,b,c,d)
  6.   =================
  7.   #ifexist a
  8.     printl a
  9.   #endif
  10.   #ifexist b
  11.     printl b
  12.   #endif
  13.   #ifexist c
  14.     printl c
  15.   #endif
  16.   #ifexist d
  17.     printl d
  18.   #endif
  19.   printl "ok"
  20.   end macro
  21.  
  22.   macro mi(...)
  23.   =============
  24.   printl ...
  25.   end macro
  26.  
  27.  
  28.   mo 1,2,3,4,5,6,7
  29. /*
  30.   restult:
  31.   1
  32.   2
  33.   3
  34.   4
  35.   ok
  36. */
  37.  
  38.   mi 1,2,3,4,5,6,7
  39. /*
  40.   restult:
  41.   1
  42.   2
  43.   3
  44.   4
  45.   5
  46.   6
  47.   7
  48. */
  49.  
  50.   waitkey
  51.  
« Last Edit: February 04, 2015, 01:48:33 PM by Charles Pegge »