Re:Pyret: A new programming language from the creators of Ra...
by lysium on Monday November 11, 2013 @06:40AM
(#6711101)
Thank you for distinguishing bindings and assignments.
Please consider `var y := x * x` for consistency (note the ':=').
Re:Pyret: A new programming language from the creators of Ra...
by skrishnamurthi on Tuesday November 12, 2013 @05:19AM
(#6716894)
We considered it and decided against it for a few reasons.
- We want := to mean "change". The initial binding is not a change. This is precisely the "bindings and assignments" distinction you're talking about.
- A variable may in fact not be mutated.
- A small point is that we want to localize editing when making a change.
So, the way I read
var y = x * x
is, "y is currently bound to x * x. However, y is a variable, so this binding is not guaranteed to last. Be careful about assuming you know the value of y." If you then see y := x * z
it reads as "y's value changes to that of x * z".So: "=" means "introduced a name with this value"; "var" means "but this binding may change"; ":=" means "and yup, it really _did_ change".
We don't EVER use = for assignment. For us, = is binding. If you write
Pyret will say and point to the two bindings.The goal here is to make the common case work fine, where you create a bunch of distinct local bindings; but when you try to mutate, you have to do it explicitly:
The first line inside f says "y is _currently_ this, but it's variable, so look out!", and subsequent mutations use := to change y. Unlike JavaScript (say), mutating a variable that hasn't previously been defined is an error, rather than quietly adding the variable to the set of defined names.