brownplt / pyret-lang

The Pyret language.
Other
1.06k stars 106 forks source link

Equality testing with var #1256

Closed sorawee closed 6 years ago

sorawee commented 6 years ago
check:
  var a = 1
  a is 1
  a := 2
  a is 2
end

results in all tests passed. This is kinda surprising.

jpolitz commented 6 years ago

Previous discussion: https://groups.google.com/forum/#!topic/pyret-discuss/8ZWUs7R92Dg

Pretty sure this is #wontfix, but worth having it be clear what the notional machine is doing here.

blerner commented 6 years ago

Agreed #wontfix. The thing that's interesting about variables is that every use of them intrinsically dereferences them and gets their current value, and those values are indeed equal-always. (This took me a long time to wrap my head around, why e.g. in modeling \JS, refs were boxes and a variable containing a ref therefore was a box containing a box...) The language (by which I mean, all common languages with these kinds of variables) doesn't give you a way to talk about "the variable itself", because merely mentioning the variable yields its value. If we wanted to provide that ability, we could, but it would not be "how variables work in C/Java/ScriptyLanguageDuJour/etc".

shriram commented 6 years ago

But just to note, this is confusing as heck for students. The situation is worse in Pyret/PAPL than elsewhere because we go so far out of our way to talk carefully about equality, so they are certain that something "interesting" (-now-ish) should happen for variables…and it doesn't! Of course, that just means the notional machine needs to be even clearer (CC @prestontw).