summaryrefslogtreecommitdiffstats
path: root/samples/list.slam
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-18 09:39:53 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-18 09:39:53 +0200
commitdc1ef25f1a7f8e36e93928e5b0288e203833e14a (patch)
treeb2baa429efd629e55bcd8455a5e46be198d2eba1 /samples/list.slam
parent7a6dc3758c361aa7685934a1896db9f23f1d74be (diff)
Clean up
Diffstat (limited to 'samples/list.slam')
-rw-r--r--samples/list.slam27
1 files changed, 27 insertions, 0 deletions
diff --git a/samples/list.slam b/samples/list.slam
new file mode 100644
index 0000000..c0fa5da
--- /dev/null
+++ b/samples/list.slam
@@ -0,0 +1,27 @@
+define prepend
+ $prepend_val !
+ $prepend_phrase !
+ '[ $prepend_val @ $prepend_phrase @ unphrase '] phrase
+ $prepend_val forget $prepend_phrase forget
+ ;
+
+define append
+ $append_val !
+ $append_phrase !
+ '[ $append_phrase @ unphrase $append_val @ '] phrase
+ $append_val forget $append_phrase forget
+ ;
+
+define stack-empty? stack-size 0 eq? ;
+
+define ..
+ [ stack-empty? not ]
+ [ . ] loop
+ ;
+
+[ 2 3 ] 1 prepend .
+[ 2 3 ] 4 append .
+[ 1 2 3 ] pop $1 ! pop $2 ! pop $3 !
+$1 ?
+$2 ?
+$3 ?