diff --git a/book/the-lox-language.md b/book/the-lox-language.md index 48b8fe3db..4c8eb9124 100644 --- a/book/the-lox-language.md +++ b/book/the-lox-language.md @@ -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. diff --git a/test/benchmark/mandelbrot.lox b/test/benchmark/mandelbrot.lox new file mode 100644 index 000000000..7c53726ef --- /dev/null +++ b/test/benchmark/mandelbrot.lox @@ -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; +} \ No newline at end of file