PB4 Wish - Macro parameter count and recursion

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
tinman
PureBasic Expert
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

Post by tinman »

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.
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)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I request for the most similar FASM syntax as possible :)
It's the easiest :)
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

I'll seecond the FASM request.
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

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
Ta - N
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

Mm! Ok, thanks Tinman, I get it. But... I think 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.

Appreciate your explanation, though :-)
Ta - N
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> 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. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

- 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...
Ta - N
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

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 :-))
( 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... )
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

... or "put y at BYTE(x)", it is even more readable :P
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post by Kazmirzak »

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!
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Macros are also in my wishlist, but they're not that "perfect" if not properly used, I mean, you shouldn't use them instead of procedures all the time because each time the macro is used, the PB code gets replaced by the macro code, and this *does* take space in the final exe.

Regards,
El_Choni
Post Reply