summary refs log tree commit diff
path: root/mew.scm
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2023-01-02 19:10:02 +0100
committerLeah Neukirchen <leah@vuxu.org>2023-01-02 19:10:02 +0100
commit5e79d95159a6cd680d045314fe427b263e7ab344 (patch)
treeb70a26a8bc1721ec08c270db5f1d8a704dfa6bc3 /mew.scm
parent909cf1ba9001f52afbbb6f7cfb6c919869c068ac (diff)
downloadmew-5e79d95159a6cd680d045314fe427b263e7ab344.tar.gz
mew-5e79d95159a6cd680d045314fe427b263e7ab344.tar.xz
mew-5e79d95159a6cd680d045314fe427b263e7ab344.zip
add push!, pop!
Diffstat (limited to 'mew.scm')
-rw-r--r--mew.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm
index 845a16e..f170273 100644
--- a/mew.scm
+++ b/mew.scm
@@ -16,7 +16,7 @@
      mod
      negate nth-accumulator
      odometer one-of op op*
-     per prn proj puts
+     per pop! prn proj push! puts
      rand range rep
      sample scan scan-right sing? search seq set set-at sgn
      shuffle shuffle! str slurp
@@ -1077,6 +1077,26 @@
       ((_ location n)
        (set location (- location n)))))
 
+  (define-syntax push!
+    (syntax-rules ()
+      ((_ location x)
+       (set location (cons x location)))))
+
+  (define-syntax pop!
+    (syntax-rules ()
+      ((_ location)
+       (if (null? location)
+         (error "pop from empty list")
+         (let ((r (car location)))
+           (set! location (cdr location))
+           r)))
+      ((_ location default)
+       (if (null? location)
+         default
+         (let ((r (car location)))
+           (set! location (cdr location))
+           r)))))
+
   (define (and=> x . fs)
     (and x
          (if (null? fs)