Syntax error when interpolating name of const variable


#1

When trying to create a macro involving a const declaration whose variable name is interpreted, I ran across the error: syntax: expected assignment after “const”

Trying to debug, I eventually tried dumping the expression, but unfortunately that produces the same error so I can’t see what the problem is. dump(:(const hello_five = 5)) works fine, but dump(:(const $(name)_five = 5) produces the above syntax error. How else could I try debugging this? And, does anyone know what my mistake is?


#2

Interpolation create distinct objects/expressions and will not affect the parsing of the expression. The $(name)_five will not be merged to a single symbol even if name's value is a symbol. You have to do that explicitly with name_five = Symbol(name, "_five") and interpolate the new symbol name_five


#3

Thank you! I hadn’t realized that.