Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Single assignment

Name: Anonymous 2014-03-15 5:30

In my earlier question about immutability, most answers assumed immutability meant only ``immutability of composite objects'' and not immutability of bindings.

So, what are the advantages, if any of single assignment (or, most accurately, run-time immutable bindings)?

I can't think of many other than ``I'm going to annotate this variable cause it really shouldn't change and if I accidently mess up I want the compiler to tell me''

Surely there are other reasons.

Name: Anonymous 2014-03-15 15:17

Algol 68 has immutable bindings and syntactic sugar for mutable (ref) bindings. With immutable bindings, it's possible to simulate call-by-reference and call-by-name using only call-by-value because you are passing the value itself and not a new instance or copy of the value.
string s1 = "Hello, world!",
string s2 := "Hello, world!"

The first uses = but the second uses :=. Here, the variable declaration for s2 is syntactic sugar for the identity declaration ref string s2 = loc string := "Hello, world!". The loc string is called a generator, which creates a reference. s1 does not allocate any storage but s2 does. Parameters are always passed by the immutable identity declaration.
The identity declaration can give an identifier to a "subname" of a mutable value.
ref struct(int x,y,z) s = heap struct(int x,y,z) := (2,3,4);
ref int x = x of s;
x := 7

Now s is equal to (7,3,4).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List