Possibility of "quantum" variables in Swift

Very, very simply, according to quantum physics, something is not one specific thing until observed. My idea is that Swift could have "quantum" variables that are computed and run an asynchronous function before they are read. This could look like:

Future.swift

import Foundation

@main
var thisVarBecomesRandomEveryNanosecond: Int = 0
quantum var exampleQuantumVariable: Int {
    get async {
        // ...
        return thisVarBecomesRandomEveryNanosecond
    }
}

for(1..100) {_ in
    print("\(exampleQuantumVariable)") // `exampleQuantumVariable` changes at this point
}

Why not just use a computed property?

var randomInteger: Int {
    Int.random(in: Int.min...Int.max)
}

for _ in 0..<100 {
    print(randomInteger)
}
2 Likes

isn't that just async version of lazy ?

5 Likes

Yes. I don’t know how hours of research could let me miss this.

2 Likes

For synchronous calls:

lazy var x = ...

For asynchronous calls:

async let y = ...
2 Likes