Skip to content

Writing a macro generates code utilizing NamedTuple whose value is calculated #32121

Closed
@runapp

Description

@runapp

I'm writing a macro tha packs it's parameter and @FILE into a NamedTuple and push it into a Vector, like this:

testvec=Vector{NamedTuple{(:f,:s),Tuple{Int,String}}}()
# push!(testvec,(f=0,s="abc"))
macro testm(a)
    return quote
        b=a+1
        push!(testvec,$(esc(
            (f=b,s=@__FILE__)
        )))
    end
end
@testm 2

My think is to try avoiding other ways than esc to prevent f and s from being renamed, or to make b work in escaped environment. However I tried $(esc(b))=a+1 and other escape forms, with none of them succeeded.

Any suggestions?

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviormacros@macros

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions