Re-assignment of a var is not evaluated #63

Open
dotta opened this Issue Aug 16, 2012 · 5 comments

Projects

None yet

3 participants

@dotta
Member
dotta commented Aug 16, 2012
object o {
   var a = 2                                        //> a : Int = 2
   a = 3
}
@dotta
Member
dotta commented Aug 17, 2012

Martin doesn't need this for the Coursera class, so moved it to next Milestone (we will need to hack the REPL support in the compiler to get the right behavior)

@dragos
Member
dragos commented Aug 22, 2012

I don't think this is a bug. The type of an assignment is Unit, so there is no value to display. Otherwise, we could display ()

@dotta
Member
dotta commented Aug 22, 2012

I see your point, but I think it's a matter of perception. I like the worksheet because it shows me the program's flow, and seeing updates to a var is what I'd expect. (but it may be me having a wrong expectation of course)

@luigip
luigip commented Oct 4, 2012

The type of var a = 2 is Unit as well, but we display that. I would also expect to see re-assignment of a var displayed, but I'm not sure what I would expect if it were re-assigned multiple times in a loop.

@dragos
Member
dragos commented Oct 6, 2012

Not exactly. var a = 2 is a definition, not an expression. It does not have a type (for instance, you can't assign a definition to a local variable, or pass it as argument, etc so in fact it does not have a value).

We display initial values of definitions, but not for reassignments. I don't feel that strongly about this one, but it would be an irregularity (what other expressions of type Unit should we special case?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment