Global const in struct

In #32407 I saw

struct _GLOBAL_RNG <: AbstractRNG
    global const GLOBAL_RNG = _GLOBAL_RNG.instance
end

Can someone please explain what this does?

6 Likes

Anyone? I still could not figure out what this does.

I think it just executes the code inside the struct? I wasn’t aware that something like this was possible:

julia> struct Foo
           println("Hello world!")
       end
Hello world!

@rfourquet asked about it

but got no reply.

@jameson, sorry for the direct ping, but can you please explain this code in your PR? I am rather curious.

It’s just the same as defining constructors, or whatever use you usually do:

struct A <: B
    A() = new()
    global copy() = new()
    x = 5
    println(x)
end
1 Like