Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions book/the-lox-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ All of these operators work on numbers, and it's an error to pass any other
types to them. The exception is the `+` operator -- you can also pass it two
strings to concatenate them.

### Chained Negation Example

Lox allows chaining of the logical NOT operator. This means you can write expressions like:

```lox
!!!!true; // evaluates to true
!!!false; // evaluates to true
!!false; // evaluates to false
```

### Comparison and equality

Moving along, we have a few more operators that always return a Boolean result.
Expand Down
27 changes: 27 additions & 0 deletions test/benchmark/mandelbrot.lox
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Mandelbrot
var width = 78;
var height = 44;
var max_iter = 50;

for (var y = 0; y < height; y = y + 1) {
var line = "";
for (var x = 0; x < width; x = x + 1) {
var cr = (x * 2.0 / width) - 1.5;
var ci = (y * 2.0 / height) - 1.0;
var zr = 0.0;
var zi = 0.0;
var iter = 0;
while (zr*zr + zi*zi < 4.0 and iter < max_iter) {
var tmp = zr*zr - zi*zi + cr;
zi = 2.0*zr*zi + ci;
zr = tmp;
iter = iter + 1;
}
if (iter == max_iter) {
line = line + "#";
} else {
line = line + " ";
}
}
print line;
}