How to get the type of a symbol in a macro?


#1

I want to write a macro where i can convert the symbols to types and do some type based programming?

How can i do that for ex:

@linearize Type1 Type2 Type3

Type1-3 will be accessible as a symbol within the macro but i want to access them as types.
How can i do that?

Thnks


#2

This is not possible. Macros only have access to the literal code itself, never its values (nor types). What is the actual problem you’re trying to solve?


#3

Thank you,
I was writing a linearization system, but that means, i need to stage the computation of linearization in the macro to be run at runtime.

thanks


#4

Can i use eval within the macro and get the type?
such as:
typ1=eval(Type1)


#5

You need to give it the right module. And you need to be aware that it happens at compile time. It’s valid code pattern but it may not be what you want.


#6

Maybe you actually want a @generated function instead?


#7

How?

can you show me an example which would help my case?

Thanks


#8

If you could tell us what you are trying to accomplish, it would be easier to help you implement it.