3 ms·
I don't quite get why the 'Substitutability' code snippet fails? Is it because the both vars 'point' to the same RAM address initialized with '3'? If that is th
by kelvin0 12y ago
I don't quite get why the 'Substitutability' code snippet fails? Is it because the both vars 'point' to the same RAM address initialized with '3'?
If that is the case, I would argue the language is somewhat broken, or at least it`s a major caveat ...
Please explain?
- amithgeorge 12y agoIsn't because after the increment operation, x has the value 4. Thus even if y has the value 3 and equals 3, it doesn't equal x.
- kelvin0 12y agoThe code line which 'fails' is $y == 3 , I think we are both confused ...
- tel 12y agoDon't think about RAM. Instead, consider something like the mathematical expression x = 3 = y thus `x` and `y` are both just new names for the same identical value `3`. Since both variables reference the same thing then we ought to be able to substitute x for y whenever we like. Of course, in Perl `x` isn't really a variable but instead a name referencing a "slot" which can be mutated. That mutation breaks the reference and makes `x` hold more meaning than merely a "reference to 3". So then you cannot substitute it for `y` any longer. I think his example code snippet is a little obtuse, though.