aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-20 22:47:03 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-23 18:25:23 +0300
commit4cf7c8bacfc836cff5278317cb32dc029cb87273 (patch)
tree58d30dca3fe413c146fd0020abf8796606030db5 /examples
parentc5babf57de94a9a5e35c4bbb1237f3bffd15456c (diff)
downloadlyn-4cf7c8bacfc836cff5278317cb32dc029cb87273.tar.gz
lyn-4cf7c8bacfc836cff5278317cb32dc029cb87273.zip
play around with guile as a backend
+ I have officially devolved my language into an alternative syntax for Scheme. Oh well.
Diffstat (limited to 'examples')
-rw-r--r--examples/guile.lyn18
-rw-r--r--examples/if.lyn15
-rw-r--r--examples/loop.lyn6
-rw-r--r--examples/primitive.lyn5
-rw-r--r--examples/sum.lyn18
5 files changed, 18 insertions, 44 deletions
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)