Repository: JuliaLang/julia
File: base/docs/basedocs.jl (Julia)

Code before:
Atomically perform the operations to get and conditionally set a global to
a given value.

!!! compat "Julia 1.11"
    This function requires Julia 1.11 or later.

See also [`replaceproperty!`](@ref Base.replaceproperty!) and [`setglobal!`](@ref).
"""
replaceglobal!

"""
    setglobalonce!(module::Module, name::Symbol, value,
                  [success_order::Symbol, [fail_order::Symbol=success_order]) -> success::Bool

Atomically perform the operations to set a global to
a given value, only if it was previously not set.

!!! compat "Julia 1.11"
    This function requires Julia 1.11 or later.

See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@ref).
"""
setglobalonce!

"""
    setconst!(module::Module, name::Symbol, [x])

Create or replace the constant `name` in `module` with the new value `x`.  When
replacing, `x` does not need to have the same type as the original constant.

When `x` is not given, `name` becomes an undefined constant; it cannot be read
or written to, but can be redefined.

Note that this function does not update the world age of the current task:
```
julia> begin
           const x = 1
           println(x)
           const x = 2
           println(x)
           Core.setconst!(Main, :x, 3)
           println(x)
       end
1
2
2
```

!!! compat "Julia 1.12"
    This function requires Julia 1.12 or later.  Redefining constants on earlier
    versions of Julia is unpredictable.

Review comment (suggestion):
bikeshed: I think `declare_const` might make more sense than calling it "set!"? Later we can add `declare_method` similarly. They also do not modify anything (they create a new world for possible execution, but do not change anything), so they likely should not have a `!` (similar to `Base.delete_method`)

Code after:

"""
    replaceglobal!(module::Module, name::Symbol, expected, desired,
                  [success_order::Symbol, [fail_order::Symbol=success_order]) -> (; old, success::Bool)

Atomically perform the operations to get and conditionally set a global to
a given value.

!!! compat "Julia 1.11"
    This function requires Julia 1.11 or later.

See also [`replaceproperty!`](@ref Base.replaceproperty!) and [`setglobal!`](@ref).
"""
replaceglobal!

"""
    setglobalonce!(module::Module, name::Symbol, value,
                  [success_order::Symbol, [fail_order::Symbol=success_order]) -> success::Bool

Atomically perform the operations to set a global to
a given value, only if it was previously not set.

!!! compat "Julia 1.11"
    This function requires Julia 1.11 or later.

See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@ref).
"""
setglobalonce!

"""
    declare_const(module::Module, name::Symbol, [x])

Create or replace the constant `name` in `module` with the new value `x`.  When
replacing, `x` does not need to have the same type as the original constant.

When `x` is not given, `name` becomes an undefined constant; it cannot be read
or written to, but can be redefined.

Unlike the syntax `const`, calling this function does not insert `Core.@latestworld` to update the world age of the current frame:
```
julia> begin
           const x = 1
           println(x)
           const x = 2
           println(x)
           Core.declare_const(Main, :x, 3)
           println(x)
           Core.@latestworld
           println(x)
       end
1