PB4 Wish - Macro parameter count and recursion
- tinman
- PureBasic Expert
- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
PB4 Wish - Macro parameter count and recursion
With the upcoming pb4 which is meant to have macros, it would be very cool if we could have some sort of compiler symbol which represents the number of arguments passed to a macro.
Kind of like `0 in Blitz 2 (IIRC).
Edit: being able to write recursive macros would also be an advantage.
Kind of like `0 in Blitz 2 (IIRC).
Edit: being able to write recursive macros would also be an advantage.
Last edited by tinman on Tue Oct 12, 2004 10:21 am, edited 1 time in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Dont mean to steal the thread (sorry) just 1 reply will suffice 
What will macros do for me? Do you mean <I>macros</I> in terms of recording common IDE key sequences? Or is it something more than that. Its just that there seems to be a lot of *excitement* about this - and, well - I think I must have missed the point....
In MS Excel (for instance) I can create some VBA quickly and easily by recording a Macros (format a colum, Insert a Row etc) so I think my understanding of <I>macro</I> must be different to yours...
Ta - N

What will macros do for me? Do you mean <I>macros</I> in terms of recording common IDE key sequences? Or is it something more than that. Its just that there seems to be a lot of *excitement* about this - and, well - I think I must have missed the point....
In MS Excel (for instance) I can create some VBA quickly and easily by recording a Macros (format a colum, Insert a Row etc) so I think my understanding of <I>macro</I> must be different to yours...
Ta - N
Ta - N
- tinman
- PureBasic Expert
- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
It's a sequence of code or whatever that you can insert in your code wherever you put the appropriate symbol.
Think of constants but with more complex capabilities than numbers and strings.
Think of constants but with more complex capabilities than numbers and strings.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
> if I used the same Block of code > 2 times, I'd create a procedure for it,
> so perhaps I'm not so bothered about Macros's.
Macros are not just for replacing procedures... you can replace ANY code
with a macro. For example, a lot of my apps use the MessageBeep API to
make a sound, using MessageBeep_(#MB_ICONASTERISK). With macros,
I can replace this command with something much shorter, like Chime().
Whenever the compiler sees Chime() it replaces it with the longer version.
Same functionality and end-result, but much less typing in the source.
> so perhaps I'm not so bothered about Macros's.
Macros are not just for replacing procedures... you can replace ANY code
with a macro. For example, a lot of my apps use the MessageBeep API to
make a sound, using MessageBeep_(#MB_ICONASTERISK). With macros,
I can replace this command with something much shorter, like Chime().
Whenever the compiler sees Chime() it replaces it with the longer version.
Same functionality and end-result, but much less typing in the source.

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- I think I would still use a procedure. But, if I understood ASM (for example) then I can see how this might be invaluable... In the longrun, I find it makes maintenance and Bug-fixes much easier to manage because I use descriptively named Procedures that are re-used in my code many times to describe my *logic-flow* (almost no comments). Lots of code that is replaced by the IDE sounds like hard work to maintain to me.
But that said, you and Tinman are way more competant PB'ers than I am, so although *I* dont care about Macros, its probably good that you do
- anyway, dont want to steal Tinmans thread...
But that said, you and Tinman are way more competant PB'ers than I am, so although *I* dont care about Macros, its probably good that you do

- anyway, dont want to steal Tinmans thread...
Ta - N
here's a good example for a macro
i don't like to use POKEB etc. as it's not very readable, so i'd use a macro that creates a new variation:
in pb:
POKEB( x , y )
would be:
BYTE( x ) = y
to me, the second form is much more readable than the first (well, if fred needs another wish, here is another one
)
i don't like to use POKEB etc. as it's not very readable, so i'd use a macro that creates a new variation:
in pb:
POKEB( x , y )
would be:
BYTE( x ) = y
to me, the second form is much more readable than the first (well, if fred needs another wish, here is another one

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
There is a different between macros and functions:
Maybe you want to make a collection of macros with your own commands, maybe you don't like the Word 'gagdet' and you write a macro for each gadget-function so that you now use "MoveWindow" instead of "MoveGadget" and so on (just an example)
There are two ways:
1. You write an include-file with lots of functions
2. You write an include-file with lots of macros.
The great advantage of macros is that they are only included in your code when they are needed, so your exe will still be small. Functions are all included even if they arent needed, so your exe will grow. And the second thing is that functions have a little slow down effect - because all the parameters go to the stack, then the function reads the stack - macros replace the code itself with the new code so no stack and no function call is needed!
So MACROS are perfect!
Maybe you want to make a collection of macros with your own commands, maybe you don't like the Word 'gagdet' and you write a macro for each gadget-function so that you now use "MoveWindow" instead of "MoveGadget" and so on (just an example)
There are two ways:
1. You write an include-file with lots of functions
2. You write an include-file with lots of macros.
The great advantage of macros is that they are only included in your code when they are needed, so your exe will still be small. Functions are all included even if they arent needed, so your exe will grow. And the second thing is that functions have a little slow down effect - because all the parameters go to the stack, then the function reads the stack - macros replace the code itself with the new code so no stack and no function call is needed!
So MACROS are perfect!