From d2fb5462c77ca45c309d8cf9130405d72d684222 Mon Sep 17 00:00:00 2001 From: Valentino Phiri Date: Wed, 30 Jul 2025 22:58:24 +0200 Subject: [PATCH 1/3] Update the-lox-language.md; Chained negative expression --- book/the-lox-language.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/book/the-lox-language.md b/book/the-lox-language.md index 48b8fe3db..e04eec72f 100644 --- a/book/the-lox-language.md +++ b/book/the-lox-language.md @@ -283,6 +283,15 @@ 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. From f955c518dc13030ccaf736e83e070419b8557172 Mon Sep 17 00:00:00 2001 From: Valentino Phiri Date: Wed, 30 Jul 2025 23:01:24 +0200 Subject: [PATCH 2/3] Update the-lox-language.md --- book/the-lox-language.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/book/the-lox-language.md b/book/the-lox-language.md index e04eec72f..4c8eb9124 100644 --- a/book/the-lox-language.md +++ b/book/the-lox-language.md @@ -288,9 +288,10 @@ strings to concatenate them. 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 +!!!!true; // evaluates to true +!!!false; // evaluates to true +!!false; // evaluates to false +``` ### Comparison and equality From e11bc5ccb46244d2c0cd8add16201286b77ef687 Mon Sep 17 00:00:00 2001 From: Valentino Phiri Date: Wed, 30 Jul 2025 23:07:58 +0200 Subject: [PATCH 3/3] Create mandelbrot.lox --- test/benchmark/mandelbrot.lox | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/benchmark/mandelbrot.lox 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