TodePond / DreamBerd

perfect programming language
https://dreamberd.computer
Other
11.33k stars 349 forks source link

[Feature Request] Add quantum variables #582

Open MrMxffin opened 7 months ago

MrMxffin commented 7 months ago

Examples:

// Define a quantum variable 'isCatAlive' in superposition of true and false with given probabilities
¡¡¡¡¡const quantum isCatAlive = |0.7⟩ |true⟩ + |0.3⟩ |false⟩!!!!!
¡¡print(isCatAlive)!!                                   //Prints "|0.7⟩ |true⟩ + |0.3⟩ |false⟩"
// Observing 'isCatAlive' will collapse its state
¿observe(isCatAlive)?

// Depending on the collapsed state, print different messages
if (isCatAlive) {
  ¡print("Yay")! 
} else {
  ¿¿¿¿¿print("Cool")????? 
}

// Another example showcasing the superposition of different datatypes
¡¡¡¡const quantum foo = |0.2⟩ |7⟩ + |0.8⟩ |"Yes"⟩!!!!

// Observing 'foo' will collapse its state, and the print statement below will depend on the collapsed value
¡¡¡observe(foo)!!!
¿print(foo)? 

// Functions and variables can also be used in quantum superposition
¿¿const const const pi = 3??
¡¡const quantum bar = |0.5⟩ |print("Karl Marx")⟩ + |0.5⟩ |pi⟩!! 

// Observing 'bar' will collapse its state
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡observe(bar)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// Depending on the collapsed state, it will either print "Karl Marx" or assign the value of 'pi' to 'bar'
// This will print "Karl Marx" 50% of the time and assign the value of 'pi' to 'bar' the other 50% of the time