diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-14 06:48:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-14 06:48:35 -0700 |
commit | 61617da8db174532055801a7ccdc244b8fb80f2e (patch) | |
tree | d2c861b1ce6f5dc35f241451a89068f4fc6cc34d | |
parent | 936463735640b904a97bad5588a12f9d70e88075 (diff) | |
download | txr-61617da8db174532055801a7ccdc244b8fb80f2e.tar.gz txr-61617da8db174532055801a7ccdc244b8fb80f2e.tar.bz2 txr-61617da8db174532055801a7ccdc244b8fb80f2e.zip |
New place-mutating macro: upd.
* lisplib.c (place_set_entries): Add upd to the auto-load
list for place.tl.
* share/txr/stdlib/place.tl (upd): New macro.
* txr.1: Documented.
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/place.tl | 5 | ||||
-rw-r--r-- | txr.1 | 34 |
3 files changed, 40 insertions, 1 deletions
@@ -69,7 +69,7 @@ static val place_set_entries(val dlt, val fun) lit("with-delete-expander"), lit("set"), lit("pset"), lit("zap"), lit("flip"), lit("inc"), lit("dec"), lit("push"), lit("pop"), lit("swap"), lit("shift"), lit("rotate"), - lit("pushnew"), lit("del"), lit("lset"), + lit("pushnew"), lit("del"), lit("lset"), lit("upd"), lit("defplace"), lit("define-place-macro"), lit("define-modify-macro"), lit("placelet"), lit("placelet*"), lit("define-acessor"), lit("with-slots"), diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index d580d91a..61654509 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -371,6 +371,11 @@ places)) ,orig))) +(defmacro upd (place . opip-args) + (with-gensyms (pl) + ^(placelet ((,pl ,place)) + (set ,pl (call (opip ,*opip-args) ,pl))))) + (defmacro defplace (place-destructuring-args body-sym (getter-sym setter-sym update-body) : ((ssetter-sym clobber-body)) @@ -11374,6 +11374,14 @@ Sets multiple places to values obtained from successive elements of .metn sequence . +.meIP (upd < place << opip-arg *) +Applies an +.codn opip -style +operational pipeline to the value of +.meta place +and stores the result back into +.metn place . + .PP .SS* Namespaces and Environments @@ -26545,6 +26553,32 @@ form produces the value of .meta sequence-expr as its result value. +.coNP Macro @ upd +.synb +.mets (upd < place << opip-arg *) +.syne +.desc +The +.code upd +macro evaluates +.meta place +and passes the value as an argument to the operational pipeline +function formed, +as if by the +.code opip +macro, from the +.meta opip-arg +arguments. The result of this function is then stored back into +.metn place . + +The following equivalence holds, except that place +.code p +is evaluated only once: + +.cblk + (upd p x y z ...) <--> (set p (call (opip x y z ...) p)) +.cble + .SS* User-Defined Places and Place Operators \*(TL provides a number of place-modifying operators such as .codn set , |