35 lines
908 B
Plaintext
35 lines
908 B
Plaintext
|
fn free_floating(i32 arg1, i32 arg2) ReturnType {}
|
||
|
|
||
|
// associated function for the World struct
|
||
|
World fn set_next(i32 i, i32 j) {
|
||
|
// members on this World struct can be accessed with `.`
|
||
|
var numdots = .numdots; // mutable variables are defined with `var`
|
||
|
let neighbors = count_neighbors(.current, i, j);
|
||
|
|
||
|
// `if` statements are expressions
|
||
|
let next = if .current.get(i, j) == 0 {
|
||
|
if neighbors != 3 {
|
||
|
0
|
||
|
} else {
|
||
|
numdots++;
|
||
|
1
|
||
|
}
|
||
|
} else {
|
||
|
// Python-like `or` operator
|
||
|
if neighbors == 2 or neighbors == 3 {
|
||
|
1
|
||
|
} else {
|
||
|
numdots--;
|
||
|
0
|
||
|
}
|
||
|
};
|
||
|
|
||
|
if next != 0 {
|
||
|
// TODO: mutability rules for arguments?
|
||
|
if i < .xmin { .xmin = i; }
|
||
|
if i > .xmax { .xmax = i; }
|
||
|
if j < .ymin { .ymin = j; }
|
||
|
if j > .ymax { .ymax = j; }
|
||
|
}
|
||
|
}
|