!define within a macro destroys reference

0 votes
asked Dec 6, 2018 in Bug by Remco Boerma

See for yourself.

!definelong with(x)
  !define _ x

note over wrong: a : _
note over wrong: b : _
note over wrong: a : _

!define _ x
note over right: x : _
!define _ y
note over right: y : _
!define _ x
note over right: x : _


The second `with(a)` produces a reference to `b`, not only from `_` but it wrongly changes `a`

When the same technique is used without macro substitution the right colum is produced, as would be expected. 

1 Answer

0 votes
answered Dec 7, 2018 by mgrol (2,810 points)


yes and no. Yes because it looks like it, but no because it is a homemade problem from you that comes from the way macros work. To summarize: You replaced your a already with b and you work with a chain of string substitutions. I hope the image makes it more clear, look at the variables in the left comments:


I hope it is more clear now. If you still wonder why does your right lifeline works. You always start with a clean set of variables and you have no interchained substitutes. You need to think more globally. There is currently no local scope of these substitutions.

@plantuml: Therefore, this is IMHO not a bug.



commented Dec 10, 2018 by anonymous
Thanks Michael,

I get what's going on, and then i wonder why the inconsistency would allow two different lines to be possible. Wouldn't the last !define _ x assign y to x instead of x? Why is the functionality of !define different when used in a macro and not in the main code?
Can you elaborate more on the clean set of variables?

I would love to use something like:

  send(_,another value)

or better even:

  send(another value)

which will use _ as it is set by the with macro.
I can turn this into a stack and use copy and paste between different schema's, which would serve me a lot, and give cleaner code because there's less references and more scope to use.

Looking forward to you reply
commented Dec 10, 2018 by mgrol (2,810 points)

I am not the developer of plantuml and I didn't look into the code. Please see  the link below I added some more notes to the original sequence.
Define in Macro does:
1) subsitute _ with a
2) subsitute  a with b
It is like a queue.
For the defines not within the macro
1) subsitute _ with x
2) subsitute a new _  with < because the _ from 1) is already x
It's rather difficult to grasp.

Think about using macros not to define other macros but to actually do something directly.
Global string replacements are difficult to handle.

I adopted the example from above and added some lines. I defined a new macro newWith() in which I can hand over the participant (WHERE) and the value as WHAT. Therefore, I am able to do the stuff without defining a string substitute on a global level.


Macros should be used (in my opnion)  like methods from applications/services. If you try to do something in your application by defining everything as global variables it will be pretty difficult to see all the side effects when you changed one of your globals. If you wrap your actions into macros as I did in the example above, it will get easier.

If you need a working example for a sequence diagram send me a PN with your email address.


commented Dec 11, 2018 by anonymous
Thanks Michael, that's useful.
Would love that sequence diagram as that's what i'm mostly interested in. I'll pm you my email.

I'm using macro's on a global level to easy the use of plantuml and use a more domain driven set of macro's. It would be great if some could interact on the global level.

Another question, in the same line: would you know of any way to disable macro expansion on a per use basis? Is there a way to escape a macro name in that sense?

commented Dec 11, 2018 by mgrol (2,810 points)
I already answered your PM via email, so you should have received an email shortly after 11am CET. I do have a set of globals as well as you can see in my example e.g. for the colors. However, I warned you about the side effects of changing these variables due to the side effects.
I don't really get your last questions. I'll try to answer and maybe it is the answer you were looking for. There is currently no possibility like
!definelong macro(value,boolean)
I don't know if this is somehow close to what you were asking for. If not could you maybe sketch what you expect?

Btw: This is a discussion we opened here http://wiki.plantuml.net/site/plantumlshell. However, this discussion just started.