Articles

  • No categories

Values

Unlike more traditional object-oriented languages, all compound structures (e.g. lists, sets, and records) have value semantics. This means they are passed and returned by-value in their entirety (as in Pascal, or most functional languages) rather than just having their references being passed by value (as in Java, or C#).

But, what does this mean? Well, for example, lists should not be thought of as objects; rather, they should be thought of as values. The following example illustrates why:

void ::main(System.Console console):
    xs = [1,2,3]
    ys = xs
    xs[0] = 2
    console.out.println(str(xs))
    console.out.println(str(ys))

The above code will print [2,2,3] for xs, followed by [1,2,3] for ys. Thus, the assignment to index 0 of xs does not affect the value of ys. This differs from a language like Java, where one could affect the other.