summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-04-08 15:28:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-04-08 15:28:16 -0700
commit279a8b5800d971fe205308f5c753a53fd455611c (patch)
tree1ace122cc5a8117776a7d89a2c833ffa02d3c8af
parent98b0ac5ec8c2a750462d830810ea2ba9de91e57b (diff)
downloadtxr-279a8b5800d971fe205308f5c753a53fd455611c.tar.gz
txr-279a8b5800d971fe205308f5c753a53fd455611c.tar.bz2
txr-279a8b5800d971fe205308f5c753a53fd455611c.zip
New macros: mul and div.
* autoload.c (place_set_entries): Add mul and div symbols as autoload triggers. * stdlib/place.tl (mul, div): New macros. * txr.1: Documented.
-rw-r--r--autoload.c2
-rw-r--r--stdlib/place.tl8
-rw-r--r--txr.124
3 files changed, 33 insertions, 1 deletions
diff --git a/autoload.c b/autoload.c
index b666e386..377a54dd 100644
--- a/autoload.c
+++ b/autoload.c
@@ -101,7 +101,7 @@ static val place_set_entries(val fun)
lit("with-update-expander"), lit("with-clobber-expander"),
lit("with-delete-expander"),
lit("set"), lit("pset"), lit("zap"), lit("flip"), lit("inc"), lit("dec"),
- lit("pinc"), lit("pdec"),
+ lit("pinc"), lit("pdec"), lit("mul"), lit("div"),
lit("set-mask"), lit("clear-mask"),
lit("push"), lit("pop"), lit("swap"), lit("shift"), lit("rotate"),
lit("test-set"), lit("test-clear"), lit("compare-swap"),
diff --git a/stdlib/place.tl b/stdlib/place.tl
index 993dd75c..cd6cbd9d 100644
--- a/stdlib/place.tl
+++ b/stdlib/place.tl
@@ -283,6 +283,14 @@
(with-update-expander (getter setter) place env
^(,setter (logand (,getter) (lognot (logior ,*integers))))))
+(defmacro mul (place factor :env env)
+ (with-update-expander (getter setter) place env
+ ^(,setter (* (,getter) ,factor))))
+
+(defmacro div (place factor :env env)
+ (with-update-expander (getter setter) place env
+ ^(,setter (/ (,getter) ,factor))))
+
(defmacro swap (place-0 place-1 :env env)
(with-gensyms (tmp)
(with-update-expander (getter-0 setter-0) place-0 env
diff --git a/txr.1 b/txr.1
index ebe010dc..508682b5 100644
--- a/txr.1
+++ b/txr.1
@@ -44944,6 +44944,30 @@ then
is returned, otherwise
.codn nil .
+.coNP Macros @ mul and @ div
+.synb
+.mets (mul << place < factor )
+.mets (div << place < factor )
+.syne
+.desc
+The
+.code mul
+and
+.code div
+macros update
+.meta place
+by scaling its value by
+.metn factor .
+
+The following equivalences hold, except that the operand
+.code x
+is evaluated only once:
+
+.verb
+ (mul x y) <--> (set x (* x y))
+ (div x y) <--> (set x (/ x y))
+.brev
+
.coNP Macro @ swap
.synb
.mets (swap < left-place << right-place )