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

**URL:** <https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016>\
**Category:** General Usage\
**Created:** [June 27, 2018, 10:49pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016 "2018-06-27T22:49:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [June 27, 2018, 10:49pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/1 "2018-06-27T22:49:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 27, 2018, 10:50pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/2 "2018-06-27T22:50:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [June 27, 2018, 10:58pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/3 "2018-06-27T22:58:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [June 27, 2018, 11:22pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/4 "2018-06-27T23:22:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 27, 2018, 11:34pm UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/5 "2018-06-27T23:34:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 28, 2018, 12:23am UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/6 "2018-06-28T00:23:30Z")

</div>

Maybe you actually want a [`@generated` function](https://docs.julialang.org/en/v0.6.1/manual/metaprogramming/#Generated-functions-1) instead?

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [June 28, 2018, 1:51am UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/7 "2018-06-28T01:51:51Z")

</div>

How?

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

Thanks

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 28, 2018, 5:28am UTC](https://discourse.julialang.org/t/how-to-get-the-type-of-a-symbol-in-a-macro/12016/8 "2018-06-28T05:28:22Z")

</div>

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