From 4cf7c8bacfc836cff5278317cb32dc029cb87273 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 20 Oct 2024 22:47:03 +0300 Subject: play around with guile as a backend + I have officially devolved my language into an alternative syntax for Scheme. Oh well. --- examples/guile.lyn | 18 ++++++++++++++++++ examples/if.lyn | 15 --------------- examples/loop.lyn | 6 ------ examples/primitive.lyn | 5 ----- examples/sum.lyn | 18 ------------------ 5 files changed, 18 insertions(+), 44 deletions(-) create mode 100644 examples/guile.lyn delete mode 100644 examples/if.lyn delete mode 100644 examples/loop.lyn delete mode 100644 examples/primitive.lyn delete mode 100644 examples/sum.lyn (limited to 'examples') diff --git a/examples/guile.lyn b/examples/guile.lyn new file mode 100644 index 0000000..9d7f445 --- /dev/null +++ b/examples/guile.lyn @@ -0,0 +1,18 @@ +define-syntax-rule (for init condition post body) { + expand init + do () ((not (expand condition))) { + expand body + expand post + } +} + +define (sum n) { + define s 0 + for (define i 0) (< i n) (set! i (1+ i)) { + set! s (+ s i) + } + get s +} + +display (sum 1000000) +newline diff --git a/examples/if.lyn b/examples/if.lyn deleted file mode 100644 index 294a490..0000000 --- a/examples/if.lyn +++ /dev/null @@ -1,15 +0,0 @@ -# `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/loop.lyn b/examples/loop.lyn deleted file mode 100644 index 0304672..0000000 --- a/examples/loop.lyn +++ /dev/null @@ -1,6 +0,0 @@ -let sum 0 -for {let i 0} {< i 1000000} {set i (+ i 1)} { - set sum (+ sum i) -} - -println sum diff --git a/examples/primitive.lyn b/examples/primitive.lyn deleted file mode 100644 index 4ebcf74..0000000 --- a/examples/primitive.lyn +++ /dev/null @@ -1,5 +0,0 @@ -let x 0 -println x - -set x 1 -println x diff --git a/examples/sum.lyn b/examples/sum.lyn deleted file mode 100644 index 55338f6..0000000 --- a/examples/sum.lyn +++ /dev/null @@ -1,18 +0,0 @@ -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