Are integers immutable and are they acceptable as keys in

I was reading about Mutable Composite Types, and it says:

In particular, this means that small enough immutable values like integers and floats are typically passed to functions in registers (or stack allocated).

Are integers really immutable? Can they safely be used as keys in a dictionary?

Yes and yes (assuming you mean some concrete type like Int or Int64 or Int32). In fact, Ints are “bits” types, which is an even stricter subset of immutability:

help?> isbitstype
search: isbitstype

  isbitstype(T)

  Return true if type T is a "plain data" type, meaning it is immutable and contains no references to other values,
  only primitive types and other isbitstype types. 
julia> isbitstype(Int)
true
3 Likes