Menu

Notes on the Pascal source code

Alan Canon

Pascal "var" parameters

Some of the functions/procedures in the Pascal sources use "var" parameters, in which an external variable is passed by reference. Modification to the values of these parameters within the function or procedure result in the modification of the variable in the calling routine.

procedure Draw (which: integer; params: CumParams; x, y, xCenter: integer; var ySeg: integer);
function FindNth (which, pick: integer; var count: integer): integer;

To support this functionality in Java, a ''MutableInteger'' class is used. This class wraps a private integer whose value is read and set using accessor methods:

package net.richarddawkins.watchmaker.arthromorphs;

public class MutableInteger {
    private int value;

    public MutableInteger(int thevalue) {
        value = thevalue;
    }

    public MutableInteger() { }

    public int getValue() {
        return value;
    }

    public void setValue(int thevalue) {
        value = thevalue;
    }
}

Related

Wiki: Home

MongoDB Logo MongoDB