Shortening a Macro with a Macro = Linefeed

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Shortening a Macro with a Macro = Linefeed

Post by Kurzer »

Hello,

I try to shorten a code by using macros. And I als otry to shorten the Macro keyword itselb by a Marco:

Code: Select all

Macro M(a,b):Macro a:b:EndMacro
;M(C,"world"):EndMacro
Macro C:"world":EndMacro
	
sText.s = "Hello " + C
MessageRequester("", sText)
Apart from the fact that I was able to also shorten the EndMacro keyword with older PurBasic versions, which doesn't work anymore with the current PureBasic version, I now have the problem that a shortened macro keyword works, but apparently creates a superfluous linefeed.

To illustrate what I mean, please run the example code. Then comment the 3. Line, uncomment the 2. line and run the code again. Now you see a linefeed was generated between "Hello" + and the Macro C which breaks the code.

I think this is a bug, what do you think?

Regards, Kurzer

PS: In older Versions of PB this cheat was possible to reduce source code size:

Code: Select all

Macro M(a,b):Macro a:b:EndMacr:EndMacro
M(H,"Hello world")o
Debug H
Last edited by Kurzer on Thu Apr 18, 2019 11:44 am, edited 1 time in total.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Shortening a Macro with a Macro = Linefeed

Post by #NULL »

Actually the code shown in the syntax error popup window is valid code:

Code: Select all

sText.s = "Hello " + 
"world"
So I think the syntax error is not the linebreak.
If you transform

Code: Select all

Macro M(a,b):Macro a:b:EndMacro
M(C,"world"):EndMacro
;Macro C:"world":EndMacro
   
sText.s = "Hello " + C
MessageRequester("", sText)
into

Code: Select all

Macro M(a,b)
  Macro a
    b
  EndMacro
  M(C,"world")
EndMacro
;Macro C:"world":EndMacro
   
sText.s = "Hello " + C
MessageRequester("", sText)
by adding linebreaks then it works(?). Is that what you mean? That line concatenation via : (colon) does not work? I just wonder why macro C is defined at all because M is not evoked outside its own definition in the first place. Maybe it just works by accident and there is no real nesting of macro definitions.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Shortening a Macro with a Macro = Linefeed

Post by #NULL »

If you evoke M outside of M to define C then you get syntax error at second EndMacro which looks like nested macros are not expected (supported).

Code: Select all

Macro M(a,b)
  Macro a
    b
  EndMacro
EndMacro
;Macro C:"world":EndMacro
M(C,"world")
sText.s = "Hello " + C
MessageRequester("", sText)
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Shortening a Macro with a Macro = Linefeed

Post by Kurzer »

Nice find, #NULL.

Even this version works:

Code: Select all

Macro M(a,b):Macro a
b:EndMacro: M(C,"world"):EndMacro
sText.s = "Hello " + C:MessageRequester("", sText)
So the problem only occours, if we have a colon (:) between the Macro parameters 'a' and 'b' in the Macro definition.

It also gets very confusing if you append the last line with a colon to the line before the last line.

Code: Select all

Macro M(a,b):Macro a
b:EndMacro: M(C,"world"):EndMacro: sText.s = "Hello " + C:MessageRequester("", sText)
The code will be compiled, but the MessageRequester will now show "Hello 0" instead of "Hello World". - crazy!!!

I think this problem was intoduced while implementing the modules in PureBasic, because of the '::' concatenator.
The IDE have to handle with the '::' and I think this leads to the problems descibed in this thread.

In summary, I'd say the weird 'Macro behavior' is a bug. What do the other user think?

Btw: This has never worked before:

Code: Select all

Makro M (a, b) 
  Makro a 
    b 
  EndMacro 
EndMacro 
; Makro C: "Welt": EndMacro 
M (C, "Welt") 
sText.s = "Hallo" + C 
MessageRequester ("", sText)
One have to remove at least the o from EndMarco within the Macro definition.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
Post Reply