aboutsummaryrefslogtreecommitdiff
path: root/examples/sum.lyn
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-15 22:26:00 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-23 18:25:17 +0300
commit18262dcbecd97591dd15ee9274a81abb8c2ba1c4 (patch)
treed0528b89d2c13ecdc69475c390281db0fd94cdb1 /examples/sum.lyn
downloadlyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.tar.gz
lyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.zip
initial musings
Diffstat (limited to 'examples/sum.lyn')
-rw-r--r--examples/sum.lyn18
1 files changed, 18 insertions, 0 deletions
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)