# 'Int' as a reserved word

**URL:** <https://discourse.julialang.org/t/int-as-a-reserved-word/108322>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 4, 2024, 1:36am UTC](https://discourse.julialang.org/t/int-as-a-reserved-word/108322 "2024-01-04T01:36:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [January 4, 2024, 1:36am UTC](https://discourse.julialang.org/t/int-as-a-reserved-word/108322/1 "2024-01-04T01:36:33Z")

</div>

My code has such a line

```julia
Int=sparse(COO1[1,:],COO1[2,:],COO1[3,:],dim,dim)

```

It got an error:

```julia
ERROR: cannot assign a value to imported variable Core.Int from module Main

```

It seems that ‘Int’ is a reserved word of julia. How can I check whether a variable name is reserved or not?

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [January 4, 2024, 4:14am UTC](https://discourse.julialang.org/t/int-as-a-reserved-word/108322/2 "2024-01-04T04:14:43Z")

</div>

I mean, you’ve already experienced one way that you can check: if you try to assign to a variable name and get the error you just got, that name is unavailable (in current module scope). Beyond that, the answer to your question somewhat depends on why you want to do this:

1. Are you wanting to programmatically find out what names are available for assignment for the purpose of e.g. writing some developer tooling?
2. Do you just want to be able to use the names you want even if they’re defined elsewhere?
3. Do you not want your long-running calculation to error out after 30 minutes because you have a `Int=5` statement somewhere in your code, so you want advance notice if you ever make this error?

For 1, doing this programmatically isn’t necessarily as easy as it seems like it should be. Basically what you’re asking is to get a list of all symbols defined in a specific module. Theoretically, I think this is what the `names` function is intended to be for, but practically it doesn’t get you there. The best answer I’ve seen is [from Tim Holy a few years ago](https://discourse.julialang.org/t/listing-all-names-available-in-a-module-part-2/33796/2):

```julia
function namesin(mymod)
    nms = names(mymod; imported=true)
    for mod in Base.loaded_modules_array()
        if isdefined(mymod, nameof(mod))
            append!(nms, names(mod))
        end
    end
    nms
end

```

And then you could use this funciton to check whether e.g. `Int` is already assigned:

```julia-repl
julia> :Int in namesin(Main)
true

julia> :other_symbol in namesin(Main)
false

```

For 2, you do have options: you can create a module without `Int` defined within it, or you can use `let` to shadow variable names within the `let`-block’s scope:

```julia-repl
julia> baremodule ThisModuleOnlyImportsCore
           Int = 5
       end
Main.ThisModuleOnlyImportsCore

julia> ThisModuleOnlyImportsCore.Int
5

julia> let Int=6
           x = Int + 3
           println(x)
           println("let statements always assign to a new variable location instead of trying to assign to existing")
       end
9
let statements always assign to a new variable location instead of trying to assign to existing

```

For 3, I believe the linting capability of LanguageServer.jl (used in e.g. the julia vs-code extension) should catch this, but don’t quote me on that.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [January 4, 2024, 4:35am UTC](https://discourse.julialang.org/t/int-as-a-reserved-word/108322/3 "2024-01-04T04:35:22Z")

</div>

To clarify, you can assign to the variable `Int`, as long as you haven’t already used the `Int` that was imported from Core. Try this in a fresh Julia session:

```julia-repl
julia> Int = 1
1

```

The issue you illustrated only happens if you’ve already used `Int` from Core before you try to assign to it. The same thing happens with any other variables exported from a module, as you can see in this example:

```julia-repl
julia> module A
       x = 1
       export x
       end
Main.A

julia> using .A

julia> x
1

julia> x = 10
ERROR: cannot assign a value to imported variable A.x from module Main

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [January 4, 2024, 6:17am UTC](https://discourse.julialang.org/t/int-as-a-reserved-word/108322/4 "2024-01-04T06:17:28Z")

</div>

> [@jiang\_ming\_zhang](#):
>
> It seems that ‘Int’ is a reserved word of julia.

Just to state this explicitly: `Int` is not a reserved name in Julia. You can find a list of reserved names in the Manual, here: [Keywords](https://docs.julialang.org/en/v1/base/base/#Keywords).
