diff options
-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 , |