Open RoniJacobson opened 1 year ago
Good question! Changing Date.now()
just changes the clock, not the passage of time.
const const name<1s> = "Luke"!
print(name)! // "Luke"
Date.now() -= 3s!
print(name)! // "Luke"
await sleep(2s)!
print(name)! // Error
reverse
is a syntax-only change. It just flips your code lines around. I've annotated each line with the remaining lifetime of name
.
var const flip = false!
const const name<7> = "Luke"! // life: 7
if (flip) reverse! // life: 6
print(name)! // life: 5
flip = true! // life: 4
reverse! // life: 3
When it hits the bottom-line reverse it becomes this:
reverse! // life: 3
flip = true! // life: 2
print(name)! // life: 1
if (flip) reverse! // life: 0!
const const name<7> = "Luke"!
var const flip = false!
Which then becomes:
var const flip = false!
const const name<7> = "Luke"!
if (flip) reverse! // life: 0
print(name)! // life: 0
flip = true! // life: 0
reverse! // life: 0
etc...
The thing that was unclear was how lifetimes were implemented, because I can theoretically see two ways:
If I understand you correctly, you are saying option 2 is the correct one
As of now, if you define a variable with a lifetime, and then change the time, it can lead to UB:
Does the lifetime tick down while the variable exists, or is the lifetime pinned to a certain time? A similar problem exists when discussing the reverse keyword - does the lifetime end when a certain line is reached, or after a certain amount of lines are traversed?