summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--mew.scm18
-rw-r--r--mew.svnwiki5
-rw-r--r--tests/test.mew10
3 files changed, 31 insertions, 2 deletions
diff --git a/mew.scm b/mew.scm
index 7707851..845a16e 100644
--- a/mew.scm
+++ b/mew.scm
@@ -3,13 +3,13 @@
      act accumulate andloc app at
      boolean
      comp cross-product
-     dec def del-at div dup
+     dec dec! def del-at div dup
      empty? eof esc
      fail fin final for for/into fun*
      gconcatenate gen generator-xfold generic-for-each genumerate get
      gfix giterate gmatch gpick group-by-accumulator gslice-when
      gsplit gsplit-on gwindow
-     imp inc inject inject-accumulator into
+     imp inc inc! inject inject-accumulator into
      juxt
      keys
      len lines loc
@@ -1063,6 +1063,20 @@
       ((_ location . fs)
        (set location (=> location . fs)))))
 
+  (define-syntax inc!
+    (syntax-rules ()
+      ((_ location)
+       (inc! location 1))
+      ((_ location n)
+       (set location (+ location n)))))
+
+  (define-syntax dec!
+    (syntax-rules ()
+      ((_ location)
+       (dec! location 1))
+      ((_ location n)
+       (set location (- location n)))))
+
   (define (and=> x . fs)
     (and x
          (if (null? fs)
diff --git a/mew.svnwiki b/mew.svnwiki
index 00b4724..16dd90d 100644
--- a/mew.svnwiki
+++ b/mew.svnwiki
@@ -144,6 +144,11 @@ with a {{'message}} of {{<message>}} passed through {{format}} with
 
 Increment or decrement the argument by 1.
 
+<procedure>(inc! <loc> [<n>])</procedure>
+<procedure>(dec! <loc> [<n>])</procedure>
+
+Increment or decrement the location {{<loc>}} by {{<n>}} (default: 1).
+
 <procedure>(div <num> <num>)</procedure>
 
 Alias for {{floor-quotient}}.
diff --git a/tests/test.mew b/tests/test.mew
index b7e5da7..44fdb95 100644
--- a/tests/test.mew
+++ b/tests/test.mew
@@ -97,6 +97,11 @@
   (test 3/2 (inc 1/2))
   (test-error (inc "foo")))
 
+(test-group "inc!"
+  (test 7 (loc (x 5) (inc! x) (inc! x) x))
+  (test 6 (loc (x 5) (inc! x)))
+  (test 7 (loc (x 5) (inc! x 2))))
+
 (test-group "dec"
   (test 4 (dec 5))
   (test -2 (dec -1))
@@ -104,6 +109,11 @@
   (test -1/2 (dec 1/2))
   (test-error (dec "foo")))
 
+(test-group "dec!"
+  (test 5 (loc (x 7) (dec! x) (dec! x) x))
+  (test 5 (loc (x 6) (dec! x)))
+  (test 5 (loc (x 7) (dec! x 2))))
+
 (test-group "boolean"
   (test #f (boolean #f))
   (test #t (boolean #t))