From 267e5bc78d0634bf84c287a662da6f797d309cc7 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 12 Jul 2024 23:01:44 +0200 Subject: [PATCH] Examples: Add mandelbrot.apfl It's a nice little benchmark. At the moment we need to manually call the garbage collection, otherwise it eats too much memory and takes forever. The goal is to be able to remove this call and it not wasting too much memory. --- examples/mandelbrot.apfl | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/mandelbrot.apfl diff --git a/examples/mandelbrot.apfl b/examples/mandelbrot.apfl new file mode 100644 index 0000000..3c3ec27 --- /dev/null +++ b/examples/mandelbrot.apfl @@ -0,0 +1,41 @@ +width := 80 +height := 24 +maxiter := 100 + +V+ := { a1::b1 a2::b2 -> + (+ a1 a2)::(+ b1 b2) +} + +V* := { a1::b1 a2::b2 -> + (- (* a1 a2) (* b1 b2))::(+ (* a1 b2) (* b1 a2)) +} + +Vsqared := { x -> V* x x } + +Vsqared-abs := { a::b -> + + (* a a) (* b b) +} + +mandel := { +0 _ _ -> true +_ _ _?(has Vsqared-abs > 4) -> false +n c z -> mandel (-- n) c (V+ (Vsqared z) c) +} + +mindim := if (< width height) {width} {height} +scale := / 2 mindim +iterdim := { dim body -> + half := / dim 2 + for (- half) half { x -> + body (* scale x) + } +} + +iterdim height { b -> + line := "" + iterdim width { a -> + line = & line (if (mandel maxiter a::b 0::0) {"#"} {" "}) + } + gc 'collect + print line +}