It is currently Fri Dec 13, 2019 1:34 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Shortening a Macro with a Macro = Linefeed
PostPosted: Wed Apr 17, 2019 8:39 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 502
Location: Germany / one of the fishheads
Hello,

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

Code:
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:
Macro M(a,b):Macro a:b:EndMacr:EndMacro
M(H,"Hello world")o
Debug H

_________________
PB 5.71 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 51y
"Happiness is a pet." | "Never run a changing system!"


Last edited by kurzer on Thu Apr 18, 2019 11:44 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Shortening a Macro with a Macro = Linefeed
PostPosted: Thu Apr 18, 2019 8:00 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1160
Location: right here
Actually the code shown in the syntax error popup window is valid code:
Code:
sText.s = "Hello " +
"world"
So I think the syntax error is not the linebreak.
If you transform
Code:
Macro M(a,b):Macro a:b:EndMacro
M(C,"world"):EndMacro
;Macro C:"world":EndMacro
   
sText.s = "Hello " + C
MessageRequester("", sText)
into
Code:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shortening a Macro with a Macro = Linefeed
PostPosted: Thu Apr 18, 2019 8:07 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1160
Location: right here
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:
Macro M(a,b)
  Macro a
    b
  EndMacro
EndMacro
;Macro C:"world":EndMacro
M(C,"world")
sText.s = "Hello " + C
MessageRequester("", sText)


Top
 Profile  
Reply with quote  
 Post subject: Re: Shortening a Macro with a Macro = Linefeed
PostPosted: Thu Apr 18, 2019 12:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 502
Location: Germany / one of the fishheads
Nice find, #NULL.

Even this version works:
Code:
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:
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:
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 5.71 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 51y
"Happiness is a pet." | "Never run a changing system!"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Baidu [Spider] and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye