Allow macro expansion on default macro value

0 votes
asked Jan 4 in Wanted features by Anthony-Gaudino (7,630 points)
edited Jan 6 by Anthony-Gaudino

When using default macro arguments, we must add the value in comma ("" or '') this means that we can't use a macro as the default value.

For example, this gives a syntax error:

!define FOO myclass

!define BAR(name = FOO) class name

This also won't work: 

!define FOO "myclass"

!define BAR(name = FOO) class name

Actually I think that the proper way to handle it would be to add  the string as is and then check if the resulting string has any macro, if yes, then expand those, if the resulting string still contains macros, then expand those, and keep doing it until there's no more expansions.

So, this example:

!define ABC "myclass"

!define FOO ABC as ABC

!define BAR(name = "FOO") class name


Would result in: class "myclass" as "myclass"

1 Answer

0 votes
answered Jan 31 by mgrol (1,700 points)


your idea sounds interesting. Your current problem is really that you could easily run into a recursion problem.

!define BAR(cname="FOO") class cname
!define FOO ABC
!define ABC "myClass"


myClass <|-- A
yourClass <|-- myClass

This works unless you try to use the preprocessing feature "name##text". Your difficulty could be that you mix submacros and code words (here "as").