question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro: replace order bug(?)

See original GitHub issue

There some problem that short variables can to brake more long variables:

#def MACRO1$(Dx$; x$)
    x$ + Dx$
#end def
#def MACRO2$(x$; Dx$)
    x$ + Dx$
#end def

MACRO1$(10; 20)'shows 20+10=30
MACRO2$(10; 20)'Error in "10 + D10" on line [2]: Undefined variable or units: "D10".

I’m not shure is it bug or not, but can we replace variables from long to short order?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Proektsoftbgcommented, Aug 16, 2022

Yes, It is a bug. Variables are parsed from longer to shorter. But for replacement, I simply used the string.Replace() method in C#, cycling through the parameter in their original order. The best way is to write custom replace method that does the job in just one pass, but it will take time.

Now, I can make a quick fix by preliminary sorting the parameters by their length - from longer to shorter and perform the replacement in this order.

0reactions
csercommented, Aug 17, 2022

Thanks! It works correctly now (so big problems not found at least)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Macro evaluation order [duplicate] - c++
An argument is macro-replaced before it is substituted into the replacement list, except where it appears as the operand of # (stringize) or...
Read more >
Search & replace macro returns error
I'm trying to run what I thought was a simple search & replace macro in Word 2011, to replace manual line breaks with...
Read more >
Replacing text macros
Object-like macros replace every occurrence of defined identifier with replacement-list. Version (1) of the #define directive behaves ...
Read more >
Replacing text macros
Object-like macros replace every occurrence of a defined identifier with replacement-list. Version (1) of the #define directive behaves ...
Read more >
PRE01-C. Use parentheses within macros around ...
Macro replacement lists should be parenthesized. Noncompliant Code Example. This CUBE() macro definition is noncompliant because it fails to parenthesize the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found