# Why a symbol starting with a number needs to be between brackets?

**URL:** <https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901>\
**Category:** New to Julia\
**Created:** [February 24, 2021, 12:38am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901 "2021-02-24T00:38:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 24, 2021, 12:38am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/1 "2021-02-24T00:38:10Z")

</div>

For example

```julia
function dayp(interval = :1day) # errors
   if interval == :1day
        return 1
    elseif interval == :1week
        return 7
    end
end

```

One needs to do:

```julia
function dayp(interval = :(1day))
...

```

and then call the function using: `dayp(:(1day))`

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 24, 2021, 12:48am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/2 "2021-02-24T00:48:16Z")

</div>

it’s a parsing thing, I’m not sure why but `:1` gets parsed as `1`, so it tries to do `1 * day`.

You want `Symbol("1day")`, as `:(1day)` is creating an expression, which is different.

---

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 24, 2021, 1:11am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/3 "2021-02-24T01:11:38Z")

</div>

[pdeffebach](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/2) thank you very much for the explanation. But then, I suppose, one has to call the function as `dayp(Symbol("1day"))` which is not very convenient. In this case it would possibly make more sense to use just `Strings` instead of `Symbols`, something I would like to avoid since I am using `Symbols` everywhere else.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 24, 2021, 1:15am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/4 "2021-02-24T01:15:11Z")

</div>

Yeah. Or use `day1` instead of `1day`

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 24, 2021, 1:32am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/5 "2021-02-24T01:32:41Z")

</div>

If you are using `Symbol`s because their literals are just a single character shorter than `String` characters, well, then this really throws a wrench at your choice. However, if you choose to use `Symbol` for any better reason, then the fact it become more verbose should not be so much of a problem.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 24, 2021, 1:34am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/6 "2021-02-24T01:34:35Z")

</div>

Or yet, use `:one_day` (if `"1day"` is not a viable option).

---

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 24, 2021, 1:48am UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/7 "2021-02-24T01:48:23Z")

</div>

Sure. The inconvenience is that the users of my scripts are students who most likely will get confused if they will need to change to strings the usual symbols they got used to. Of course they can always use instead day1 or m30 (instead of 30m for 30 minutes), which seems to be the best solution even if a little awkward at first.

---

<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:** [February 24, 2021, 7:53pm UTC](https://discourse.julialang.org/t/why-a-symbol-starting-with-a-number-needs-to-be-between-brackets/55901/8 "2021-02-24T19:53:34Z")

</div>

Alternatively, you could remove the use of Symbols entirely by making use of the built-in Date tools:

```julia
julia> using Dates

julia> function dayp(interval::DatePeriod = Day(1))
         return Dates.value(Day(interval))
       end
dayp (generic function with 2 methods)

julia> dayp(Day(1))
1

julia> dayp(Week(1))
7

julia> dayp(Week(3))
21

```

This avoids the issue you’re dealing with and avoids needing to hard-code the number of days in every possible number of weeks by hand.

You can even do:

```julia
julia> const day = Day(1)
1 day

```

and now the implicit multiplication of `1day` will actually _just work_:

```julia
julia> 1day
1 day

julia> 2day
2 days

julia> 3day
3 days

julia> dayp(3day)
3

```
