Macros: Why do middle default parameters not apply?

+1 vote
asked Apr 1, 2017 in To be sorted by anonymous

 

Is this a bug? I define a macro: myMacro() with 3 parameters: myMacro(p1, p2="def2", p3="def3"), the last 2 parameters having default values. When I call the macro like this: myMacro("a1",,"a3") there is no way to only provide arguments for parameter 1 and 3. p2 will not use its default value.

See this more elaborate example:


@startuml

skinparam noteFontSize 20

!define showIcon(iconName, iconColor="#Purple", iconSize="12") <size:iconSize><color:iconColor><iconName></color></size>

note as N1
<back:#LightGreen>//OK, uses default values for iconColor and iconSize://</back>
""Follow this showIcon("&external-link") Link.""

<back:#LightGreen>//OK, uses default value for iconSize://</back>
""Change to showIcon("&fork", "#OrangeRed")Branch //master//.""

<back:#Red>//Not OK, does not use default value for iconColor://</back>
""Modify showIcon("&wrench",,"20") Settings.""

end note

@enduml


 

1 Answer

0 votes
answered Apr 2, 2017 by plantuml (295,000 points)
edited Apr 2, 2017 by plantuml

It's more a conception issue than a real bug.
As you have stated, there is indeed no way to only provide arguments for parameter 1 and 3 only.
You can either:

  • provide only argument 1
  • provide only arguments 1 and 2
  • provide arguments 1, 2 and 3


As workaround, you have to define a second macro:
!define showIconPurple(iconName, iconSize="12") <size:iconSize><color:#Purple><iconName></color></size>

Is this a big issue for you ?

commented Apr 3, 2017 by anonymous
Thanks for the response. Well, it is not a big issue, just a bit counterintutive if the default character of parameters depends on their positional placement and if default values will only take effect if no arguments are provided for any consecutive parameters.
commented Apr 4, 2017 by plantuml (295,000 points)
...