Closed staufga0 closed 6 years ago
@kyouko-taiga is it correct in Anzen?
If I correctly understood how it works, there is no error here.
let x = 2
creates the object 2, makes a reference of x
on 2
, and x
becomes the owner of this object.
let y &- x
makes a reference between y
and the x
's object, 2
here (so there is a reference of y
on 2
)
And let z <- y
makes a reference of z
on 2
, as before, and z
becomes the new owner of 2
, (so not x
anymore)
Yes, here are an example where there is an error.
{
let x = 2
let y &- x
let z <- x
} // here x, y and z are all deleted at the end of the block, so there is no erroneous reference to the value 2
x,y,z
are marked as true
in the results table.
let x = 2
let y &- x
{
let z <- x
} // here z is deleted at the end of the block, and thus also deleted the value 2, because it owns it
// x and y both refer to the deleted value 2, and are thus in error
x,y
are marked as false
in the results table, z
is marked as true
.
Moreover, 2 examples :
let x = 2 // Creates the object 2, makes a reference of x on 2, whose x is the owner
let y = x // Create a new object 2 (different from the previous 2), makes a reference on this new object, and y is the owner of this one
And :
let z <- x + 1 // Correct, because x exists, so here, it evaluates x+1, makes a new object of it, and makes a reference of z on this new object, whose z is the owner
let w &- x + 1 // Incorrect, because there is no owner of the new object x+1, so this object cannot exist, and so w reference on nothing existing
so, in the first code : let x = 2 let y &- x let z <- y
z can obtain the ownership of the object refered by x and y but owned by x, even if y doesn't have the ownership of the object it refers to ? x can loose his ownership on the object in the statement : let z <- y ?
You are right, z
cannot get ownership because y
does not have ownership.
so, should I say that y is false, because it's used in a wrong manner, or only z is false ?
You should say that y
is false
, and z
is false
.
Ok, thank You
if I have the following code in Ansem : let x = 2 let y &- x let z <- y
z cannot be properly assigned so it is false, but should I also say that y is misused and false ?