diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-10-15 22:26:00 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-10-23 18:25:17 +0300 |
commit | 18262dcbecd97591dd15ee9274a81abb8c2ba1c4 (patch) | |
tree | d0528b89d2c13ecdc69475c390281db0fd94cdb1 /examples/sum.lyn | |
download | lyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.tar.gz lyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.zip |
initial musings
Diffstat (limited to 'examples/sum.lyn')
-rw-r--r-- | examples/sum.lyn | 18 |
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) |