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 | |
download | lyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.tar.gz lyn-18262dcbecd97591dd15ee9274a81abb8c2ba1c4.zip |
initial musings
Diffstat (limited to 'examples')
-rw-r--r-- | examples/if.lyn | 15 | ||||
-rw-r--r-- | examples/sum.lyn | 18 |
2 files changed, 33 insertions, 0 deletions
diff --git a/examples/if.lyn b/examples/if.lyn new file mode 100644 index 0000000..294a490 --- /dev/null +++ b/examples/if.lyn @@ -0,0 +1,15 @@ +# `if` macro, think of it as a statement I guess? +# else is used by the `if` command in C, presumably? +if {< i 10} { + println "a" +} {< i 20} { + println "b" +} else { + println "c" +} + +# `if` procedure, think of it as expr-if in other languages I guess +# note that all arguments get evaluated here, so if you have a slow function in +# one branch you should probably prefer `if` statements + +let x (do-if (< i 10) "a" (< i 20) "b" else "c") 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) |