/*
 * File: deep_return.txt
 * ---------------------
 */

/* If you want a function to return a variable and its sub-variables you can
   add ref before the name of the variable that you wish to return. */
Position = function(x, y) {
    p.x = x;
    p.y = y;
    p = function() {
        return "(" + tostring(this.x) + ", " + tostring(this.y) + ")";
    };
    return ref p;
};

/* In order to actually copy the entire variable, not just its intrinsic value,
   you need to make a deep assignment. */
pos := Position(5, 9);
wln(pos());

/* Doing a normal assignment will just copy the intrinsic return-value, which
   happens to be a malfunctioning function. */
wrong = Position(5, 9);
wln(wrong());

