These pages are auto-generated from self-documenting comments embedded in class files.
For more information on breve and steve, refer to the breve homepage.

## Object : PushProgram

This class is included as part of the file Push.tz.
To use this class in a simulation, include the line "@use Push."

### Class description:

> Summary: a single program in the Push programming language.

> A PushProgram object is a program in the Push programming language. To be used in conjunction with the class PushInterpreter.

### Class methods:

> Reading and writing a Push program to a file

> - read
> - write

> Parsing programs and making random code

> - make-random-code
> - parse

> Copying and evolving Push programs

> - copy-from
> - crossover
> - delete-random-subtree
> - flatten-random-subtree
> - mutate

> Getting information about a Push program

> - get-discrepancy
> - get-list
> - get-size
> - get-string
> - get-top-level-difference
> - get-top-level-size
> - set-from
> - swap-sublists

`copy-from program otherProgram (object)`

> Copies the contents of otherProgram to this object.

`crossover from-parent1 p1 (object) from-parent2 p2 (object) with-interpreter interpreter (object)`

> Sets this object to a genetic crossover of p1 and p2.

`delete-random-subtree`

> Removes a random subtree from the code.

`flatten-random-subtree`

> Flattens a random subtree in the code.

`get-discrepancy from otherProgram (object)`

> Determines the discrepancy between this program and otherProgram. This is defined as the number of points (atoms and subtrees) found in this program which do not exist in otherProgram, plus the number of points found in otherProgram that do not exist in this program.

> This method considers the order of points in a program, and considers all sublists found in a program. For this reason, it is a good measure of similarity between two evolved programs. For a simpler comparison operator, suitable for comparing lists in which order should be preserved, see get-top-level-difference.

`get-list`

> Returns a list representation of this push program.

`get-size`

> Returns the size of this push program.

`get-string`

> Returns the string representation of this push program.

`get-top-level-difference from otherProgram (object)`

> Determines the top level difference between this program and otherProgram. This is calculated by comparing each element of the program against the corresponding element of otherProgram, with every mismatch counting as one point of difference. Sublists are not considered; each element in the top level list is treated as an atomic element.

> This method is well suited for comparing lists produced as output of push programs. Because it does not consider sublists or order, it is not well suited for determining the true level of similarity between two programs as one might with to do with evolved code. For that type of functionality, see the method get-discrepancy.

`get-top-level-size`

> Returns the "top-level" size of this push program, meaning that sublists are counted as one item, and not counted recursively.

`make-random-code with-interpreter interpreter (object) max-length size = -1 (int)`

> Makes a random push program of length size. Size is an optional argument with a default value of 100. The size may also be equal to -1, which indicates that the MAX-POINTS-IN-RANDOM-EXPRESSION value from the Push configuration file should be used. The interpreter provided specifies the instruction set used to generate the random code.

`mutate with-interpreter interpreter (object) with-leaf-bias leafBias = 0.9 (float) with-size-scale sizeScale = 0.3 (float) with-max-new-code-size ignored = 0 (int)`

> Modifies this code object by mutating a subtree of the program. The leafBias parameter indicates the probability that a leaf node will be selected (as opposed to a non-leaf subtree).

> Mutation is implemented as "fair" mutation, in which the new code size is determined by the size of the subtree it is replacing, plus or minus a factor of sizeScale.

> The interpreter argument determines the instruction set used to generate the random code.

> The max-new-code-size argument is ignored, but included for backwards compatibility.

`parse program codeString (string)`

> Sets the content of this code to the newly parsed string. The with-interpreter keyword is no longer required.

`read from fileName (string)`

> Reads a push program from a text file.

`set-from code-list newCodeList (list)`

> Sets this code's object using the contents of newCodeList. The list can contain literals, sublists or subprograms.

`swap-sublists at-x x (int) at-y y (int)`

> Swaps the positions of the top level sublists x and y.

`write to fileName (string)`

> Writes this push program to a text file.

Documentation created Fri Aug 8 15:16:49 2008