# Why does Julia prefix columnames and colors with a colon :?

**URL:** <https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198>\
**Category:** New to Julia\
**Created:** [December 1, 2018, 12:42am UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198 "2018-12-01T00:42:04Z")\
**Posts on this page:** 10\
**Page:** 2

<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:** [December 3, 2018, 8:08am UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/21 "2018-12-03T08:08:58Z")

</div>

Yep, it is only exported on `master`.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [December 4, 2018, 3:53pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/22 "2018-12-04T15:53:07Z")

</div>

Q: I understand that we have both strings and symbols, and how to convert between them. (And, in many older languages, strings take the place of symbols, too.)

Other than type and notation, are there differences between them? I am guessing that any symbol can be converted into a string. is the opposite also true? any other differences one should be aware of.

---

<div class="post-metadata">

**Author:** ![WschW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wschw/32/6575_2.png) [@WschW](https://discourse.julialang.org/u/WschW)\
**Post date:** [December 4, 2018, 5:43pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/23 "2018-12-04T17:43:34Z")

</div>

Comprehensive explanation of the difference can be found here: [What is a "symbol" in Julia? - Stack Overflow](https://stackoverflow.com/questions/23480722/what-is-a-symbol-in-julia)

Summarized:

Symbol equality is faster than String equality, since symbols are interned. In AST Symbols and Strings behave very differently, as can be seen when using eval.

```julia
julia> x = 5
5

julia> eval("x")
"x"

julia> eval(:x)
5

julia> eval(Meta.quot(:x))
:x  

```

end of summery.

Yes, strings can be converted into symbols as well.

```julia
julia> string(:x)
"x"

julia> Symbol("x")
:x

```

Another difference to be aware of is that Symbols are not a subtype of AbstractString, amongst other functions they do not support they do not have length and can not be indexed into.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [December 4, 2018, 6:01pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/24 "2018-12-04T18:01:40Z")

</div>

It has occurred to me that it is probably very confusing for newcomers that `x.y` is lowered to `getfield(x, :y)`, meanwhile `x."y"` is lowered to `getfield(x, "y")`. In `getfield` operations symbols are treated specially in that you can call `getfield` with them without further qualifying them as symbols, whereas in other contexts they must be explicitly annotated with `:x`. Having spent a large amount of time messing around with Julia’s AST I find this fairly natural, but I imagine that if this feature existed when I was a newcomer to the language I would have been very confused by it.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [December 4, 2018, 7:43pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/25 "2018-12-04T19:43:06Z")

</div>

> [@WschW](#):
>
> ```julia
> julia> x = 5
> 5
> 
> julia> eval("x")
> "x"
> 
> julia> eval(:x)
> 5
> 
> julia> eval(Meta.quot(:x))
> :x  
> 
> ```
> 
> end of summery.
> 
> Yes, strings can be converted into symbols as well.
> 
> ```julia
> julia> string(:x)
> "x"
> 
> julia> Symbol("x")
> :x
> 
> ```

And I have noticed that `eval("x")` produces the same output than `eval(x)`

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [December 4, 2018, 7:45pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/26 "2018-12-04T19:45:22Z")

</div>

> [@Juan](#):
>
> And I have noticed that `eval("x")` produces the same output than `eval(x)`

Well yes, if `x == "x"` of course that would be the case.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [December 4, 2018, 7:48pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/27 "2018-12-04T19:48:30Z")

</div>

But here x is not “x” but 5.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [December 4, 2018, 8:10pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/28 "2018-12-04T20:10:40Z")

</div>

> [@Juan](#):
>
> But here x is not “x” but 5.

Huh?

```julia
julia> x = 5
5

julia> eval("x")
"x"

julia> eval(x)
5

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 4, 2018, 8:58pm UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/29 "2018-12-04T20:58:51Z")

</div>

The key is that Julia parses the text you give it before it `eval`s it. So that’s the distinction between a `String` and the general text at a REPL prompt or in a file.

```julia
julia> x = 5;

julia> Meta.parse(" x ")
:x

julia> eval(Meta.parse(" x "))
5

```

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [December 5, 2018, 12:47am UTC](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198/30 "2018-12-05T00:47:02Z")

</div>

I think it might’ve been

```julia
x=5
eval(x) == eval(:x)
```

[Previous page](https://discourse.julialang.org/t/why-does-julia-prefix-columnames-and-colors-with-a-colon/18198.md?page=1)
