How to know if top-level

My macro expands into ... export foo, which causes a

ERROR: syntax: "export" expression not at top level

I can put it in a try/catch block, but is there an @is_top_level() magic macro that I could use instead?

I wish there was something better than this kludge but afaik there’s not: Is there a way to determine whether code is toplevel? - #3 by marius311

1 Like

That’s nice, but won’t help here, because export is a syntax error. It can’t be in the macroexpansion. In fact,

I can put it in a try/catch block,

is wrong, dunno what I was thinking. Can’t exception-handle out of a syntax error…

I suppose maybe @is_top_level() && @eval export Foo ?

1 Like