From 18262dcbecd97591dd15ee9274a81abb8c2ba1c4 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 15 Oct 2024 22:26:00 +0300 Subject: initial musings --- examples/sum.lyn | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/sum.lyn (limited to 'examples/sum.lyn') diff --git a/examples/sum.lyn b/examples/sum.lyn new file mode 100644 index 0000000..a4dcf61 --- /dev/null +++ b/examples/sum.lyn @@ -0,0 +1,18 @@ +syntax for {init cond post body} { + eval init + while (eval cond) { + eval body + eval post + } +} + +def sum {n} { + require n int + let s 0 + for {let i 0} {< i n} {set i (+ i 1)} { + set s (+ s i) + } + return s +} + +println (sum 1000000) -- cgit v1.2.3